]> git.pld-linux.org Git - packages/gdb.git/blob - gdb-archer.patch
- rel 7
[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 74fff58d0076fe97c6c99d65fa58126315266646
6
7 branch `archer' - the merge of branches:
8 archer-jankratochvil-vla
9 archer-jankratochvil-watchpoint3
10 archer-jankratochvil-ifunc
11 archer-pmuldoon-next-over-throw2
12 archer-tromey-python (not a merge)
13 archer-tromey-optional-psymtab (cherry-picked from post-7.2 master)
14 #TODO:archer-tromey-threaded-dwarf
15
16
17 diff --git a/gdb/Makefile.in b/gdb/Makefile.in
18 index f07bc8b..3703dca 100644
19 --- a/gdb/Makefile.in
20 +++ b/gdb/Makefile.in
21 @@ -169,6 +169,12 @@ TARGET_SYSTEM_ROOT = @TARGET_SYSTEM_ROOT@
22  TARGET_SYSTEM_ROOT_DEFINE = @TARGET_SYSTEM_ROOT_DEFINE@
23  
24  # Did the user give us a --with-gdb-datadir option?
25 +GDB_DATADIR_PATH = @GDB_DATADIR_PATH@
26 +
27 +# The argument to --with-pythondir.  If not given, this is
28 +# GDB_DATADIR_PATH/python.
29 +pythondir = @pythondir@
30 +
31  GDB_DATADIR = @GDB_DATADIR@
32  
33  # Helper code from gnulib.
34 @@ -295,13 +301,13 @@ SUBDIR_PYTHON_SRCS = \
35         python/py-cmd.c \
36         python/py-frame.c \
37         python/py-function.c \
38 +       python/py-hooks.c \
39         python/py-inferior.c \
40         python/py-infthread.c \
41         python/py-lazy-string.c \
42         python/py-objfile.c \
43         python/py-param.c \
44         python/py-prettyprint.c \
45 -       python/py-progspace.c \
46         python/py-symbol.c \
47         python/py-symtab.c \
48         python/py-type.c \
49 @@ -780,8 +786,8 @@ config/rs6000/nm-rs6000.h top.h bsd-kvm.h gdb-stabs.h reggroups.h \
50  annotate.h sim-regno.h dictionary.h dfp.h main.h frame-unwind.h        \
51  remote-fileio.h i386-linux-tdep.h vax-tdep.h objc-lang.h \
52  sentinel-frame.h bcache.h symfile.h windows-tdep.h linux-tdep.h \
53 -gdb_usleep.h jit.h xml-syscall.h ada-operator.inc microblaze-tdep.h \
54 -psymtab.h psympriv.h
55 +gdb_usleep.h jit.h python/python.h python/python-internal.h \
56 +xml-syscall.h ada-operator.inc microblaze-tdep.h
57  
58  # Header files that already have srcdir in them, or which are in objdir.
59  
60 @@ -1301,6 +1307,12 @@ stamp-h: $(srcdir)/config.in config.status
61           CONFIG_LINKS= \
62           $(SHELL) config.status
63  
64 +.gdbinit: $(srcdir)/gdbinit.in config.status
65 +       CONFIG_FILES=".gdbinit:gdbinit.in" \
66 +         CONFIG_COMMANDS= \
67 +         CONFIG_HEADERS= \
68 +         $(SHELL) config.status
69 +
70  config.status: $(srcdir)/configure configure.tgt configure.host
71         $(SHELL) config.status --recheck
72  
73 @@ -2024,6 +2036,10 @@ py-function.o: $(srcdir)/python/py-function.c
74         $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-function.c
75         $(POSTCOMPILE)
76  
77 +py-hooks.o: $(srcdir)/python/py-hooks.c
78 +       $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-hooks.c
79 +       $(POSTCOMPILE)
80 +
81  py-inferior.o: $(srcdir)/python/py-inferior.c
82         $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-inferior.c
83         $(POSTCOMPILE)
84 @@ -2072,6 +2088,36 @@ py-value.o: $(srcdir)/python/py-value.c
85         $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-value.c
86         $(POSTCOMPILE)
87  
88 +# All python library files, with the "python/lib" stripped off.
89 +# Note that we should only install files in the "gdb" module.
90 +PY_FILES = gdb/FrameIterator.py gdb/FrameWrapper.py gdb/command/alias.py \
91 +    gdb/command/backtrace.py gdb/command/require.py \
92 +    gdb/command/pahole.py gdb/command/upto.py gdb/command/__init__.py \
93 +    gdb/command/ignore_errors.py gdb/command/save_breakpoints.py \
94 +    gdb/function/caller_is.py gdb/function/in_scope.py \
95 +    gdb/function/__init__.py gdb/backtrace.py gdb/__init__.py
96 +
97 +# Install the Python library.  Python library files go under
98 +# $(pythondir).
99 +install-python:
100 +       files='$(PY_FILES)'; for file in $$files; do \
101 +         dir=`echo "$$file" | sed 's,/[^/]*$$,,'`; \
102 +         $(SHELL) $(srcdir)/../mkinstalldirs $(DESTDIR)$(pythondir)/$$dir; \
103 +         $(INSTALL_DATA) $(srcdir)/python/lib/$$file $(DESTDIR)$(pythondir)/$$file; \
104 +       done
105 +
106 +# Other packages may have their files installed in $(pythondir).
107 +uninstall-python:
108 +       files='$(PY_FILES)'; for file in $$files; do \
109 +         slashdir=`echo "/$$file" | sed 's,/[^/]*$$,,'`; \
110 +         rm -f $(DESTDIR)$(pythondir)/$$file; \
111 +         while test "x$$file" != "x$$slashdir"; do \
112 +           rmdir 2>/dev/null "$(DESTDIR)$(pythondir)$$slashdir"; \
113 +           file="$$slashdir"; \
114 +           slashdir=`echo "$$file" | sed 's,/[^/]*$$,,'`; \
115 +         done \
116 +       done
117 +
118  #
119  # Dependency tracking.  Most of this is conditional on GNU Make being
120  # found by configure; if GNU Make is not found, we fall back to a
121 diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
122 index 1d4c38b..cafb88e 100644
123 --- a/gdb/ada-lang.c
124 +++ b/gdb/ada-lang.c
125 @@ -11114,6 +11114,7 @@ ada_operator_length (const struct expression *exp, int pc, int *oplenp,
126  
127  static int
128  ada_operator_check (struct expression *exp, int pos,
129 +                   int (*type_func) (struct type *type, void *data),
130                     int (*objfile_func) (struct objfile *objfile, void *data),
131                     void *data)
132  {
133 @@ -11128,12 +11129,15 @@ ada_operator_check (struct expression *exp, int pos,
134         break;
135  
136        default:
137 -       return operator_check_standard (exp, pos, objfile_func, data);
138 +       return operator_check_standard (exp, pos, type_func, objfile_func,
139 +                                       data);
140      }
141  
142    /* Invoke callbacks for TYPE and OBJFILE if they were set as non-NULL.  */
143  
144 -  if (type && TYPE_OBJFILE (type)
145 +  if (type && type_func && (*type_func) (type, data))
146 +    return 1;
147 +  if (type && TYPE_OBJFILE (type) && objfile_func
148        && (*objfile_func) (TYPE_OBJFILE (type), data))
149      return 1;
150  
151 diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c
152 index c0edc10..17d36b5 100644
153 --- a/gdb/amd64-linux-nat.c
154 +++ b/gdb/amd64-linux-nat.c
155 @@ -375,6 +375,20 @@ amd64_linux_dr_unset_status (unsigned long mask)
156      }
157  }
158  
159 +/* See i386_dr_low_type.detach.  Do not use wrappers amd64_linux_dr_set_control
160 +   or amd64_linux_dr_reset_addr as they would modify the register cache
161 +   (amd64_linux_dr).  */
162 +
163 +static void
164 +amd64_linux_dr_detach (void)
165 +{
166 +  int regnum;
167 +
168 +  amd64_linux_dr_set (inferior_ptid, DR_CONTROL, 0);
169 +  amd64_linux_dr_unset_status (~0UL);
170 +  for (regnum = DR_FIRSTADDR; regnum <= DR_LASTADDR; regnum++)
171 +    amd64_linux_dr_set (inferior_ptid, regnum, 0);
172 +}
173  
174  static void
175  amd64_linux_new_thread (ptid_t ptid)
176 @@ -796,6 +810,7 @@ _initialize_amd64_linux_nat (void)
177    i386_dr_low.reset_addr = amd64_linux_dr_reset_addr;
178    i386_dr_low.get_status = amd64_linux_dr_get_status;
179    i386_dr_low.unset_status = amd64_linux_dr_unset_status;
180 +  i386_dr_low.detach = amd64_linux_dr_detach;
181    i386_set_debug_register_length (8);
182  
183    /* Override the GNU/Linux inferior startup hook.  */
184 diff --git a/gdb/block.c b/gdb/block.c
185 index 48ac21b..ffcc97f 100644
186 --- a/gdb/block.c
187 +++ b/gdb/block.c
188 @@ -321,3 +321,21 @@ allocate_block (struct obstack *obstack)
189  
190    return bl;
191  }
192 +
193 +/* Return OBJFILE in which BLOCK is located or NULL if we cannot find it for
194 +   whatever reason.  */
195 +
196 +struct objfile *
197 +block_objfile (const struct block *block)
198 +{
199 +  struct symbol *func;
200 +
201 +  if (block == NULL)
202 +    return NULL;
203 +
204 +  func = block_linkage_function (block);
205 +  if (func == NULL)
206 +    return NULL;
207 +
208 +  return SYMBOL_SYMTAB (func)->objfile;
209 +}
210 diff --git a/gdb/block.h b/gdb/block.h
211 index 7eedb6c..a517e80 100644
212 --- a/gdb/block.h
213 +++ b/gdb/block.h
214 @@ -166,4 +166,6 @@ extern const struct block *block_global_block (const struct block *block);
215  
216  extern struct block *allocate_block (struct obstack *obstack);
217  
218 +extern struct objfile *block_objfile (const struct block *block);
219 +
220  #endif /* BLOCK_H */
221 diff --git a/gdb/blockframe.c b/gdb/blockframe.c
222 index 0348bf4..f01d0ee 100644
223 --- a/gdb/blockframe.c
224 +++ b/gdb/blockframe.c
225 @@ -38,6 +38,7 @@
226  #include "block.h"
227  #include "inline-frame.h"
228  #include "psymtab.h"
229 +#include "elf-bfd.h"
230  
231  /* Return the innermost lexical block in execution
232     in a specified stack frame.  The frame address is assumed valid.
233 @@ -159,6 +160,7 @@ static CORE_ADDR cache_pc_function_low = 0;
234  static CORE_ADDR cache_pc_function_high = 0;
235  static char *cache_pc_function_name = 0;
236  static struct obj_section *cache_pc_function_section = NULL;
237 +static int cache_pc_function_is_gnu_ifunc = 0;
238  
239  /* Clear cache, e.g. when symbol table is discarded. */
240  
241 @@ -169,6 +171,7 @@ clear_pc_function_cache (void)
242    cache_pc_function_high = 0;
243    cache_pc_function_name = (char *) 0;
244    cache_pc_function_section = NULL;
245 +  cache_pc_function_is_gnu_ifunc = 0;
246  }
247  
248  /* Finds the "function" (text symbol) that is smaller than PC but
249 @@ -184,7 +187,7 @@ clear_pc_function_cache (void)
250  
251  /* Backward compatibility, no section argument.  */
252  
253 -int
254 +enum find_pc_partial_function_type
255  find_pc_partial_function (CORE_ADDR pc, char **name, CORE_ADDR *address,
256                           CORE_ADDR *endaddr)
257  {
258 @@ -236,6 +239,7 @@ find_pc_partial_function (CORE_ADDR pc, char **name, CORE_ADDR *address,
259           cache_pc_function_high = BLOCK_END (SYMBOL_BLOCK_VALUE (f));
260           cache_pc_function_name = SYMBOL_LINKAGE_NAME (f);
261           cache_pc_function_section = section;
262 +         cache_pc_function_is_gnu_ifunc = TYPE_GNU_IFUNC (SYMBOL_TYPE (f));
263           goto return_cached_value;
264         }
265      }
266 @@ -258,12 +262,13 @@ find_pc_partial_function (CORE_ADDR pc, char **name, CORE_ADDR *address,
267         *address = 0;
268        if (endaddr != NULL)
269         *endaddr = 0;
270 -      return 0;
271 +      return FIND_PC_PARTIAL_FUNCTION_NOT_FOUND;
272      }
273  
274    cache_pc_function_low = SYMBOL_VALUE_ADDRESS (msymbol);
275    cache_pc_function_name = SYMBOL_LINKAGE_NAME (msymbol);
276    cache_pc_function_section = section;
277 +  cache_pc_function_is_gnu_ifunc = MSYMBOL_TYPE (msymbol) == mst_text_gnu_ifunc;
278  
279    /* If the minimal symbol has a size, use it for the cache.
280       Otherwise use the lesser of the next minimal symbol in the same
281 @@ -323,7 +328,8 @@ find_pc_partial_function (CORE_ADDR pc, char **name, CORE_ADDR *address,
282         *endaddr = cache_pc_function_high;
283      }
284  
285 -  return 1;
286 +  return cache_pc_function_is_gnu_ifunc ? FIND_PC_PARTIAL_FUNCTION_GNU_IFUNC
287 +                                       : FIND_PC_PARTIAL_FUNCTION_NORMAL;
288  }
289  
290  /* Return the innermost stack frame executing inside of BLOCK,
291 diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
292 index 6a6864c..5df336d 100644
293 --- a/gdb/breakpoint.c
294 +++ b/gdb/breakpoint.c
295 @@ -62,6 +62,7 @@
296  #include "jit.h"
297  #include "xml-syscall.h"
298  #include "parser-defs.h"
299 +#include "regcache.h"
300  
301  /* readline include files */
302  #include "readline/readline.h"
303 @@ -92,6 +93,9 @@ static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *,
304  
305  static void ignore_command (char *, int);
306  
307 +static void update_breakpoint_locations (struct breakpoint *b,
308 +                                        struct symtabs_and_lines sals);
309 +
310  static int breakpoint_re_set_one (void *);
311  
312  static void clear_command (char *, int);
313 @@ -106,6 +110,9 @@ static void break_command_1 (char *, int, int);
314  
315  static void mention (struct breakpoint *);
316  
317 +static struct bp_location *add_location_to_breakpoint (struct breakpoint *b,
318 +                                            const struct symtab_and_line *sal);
319 +
320  /* This function is used in gdbtk sources and thus can not be made static.  */
321  struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
322                                               struct symtab_and_line,
323 @@ -230,6 +237,10 @@ static void disable_trace_command (char *, int);
324  
325  static void trace_pass_command (char *, int);
326  
327 +static void gnu_ifunc_resolver_stop (struct breakpoint *b);
328 +
329 +static void gnu_ifunc_resolver_return_stop (struct breakpoint *b);
330 +
331  /* Assuming we're creating a static tracepoint, does S look like a
332     static tracepoint marker spec ("-m MARKER_ID")?  */
333  #define is_marker_spec(s)                                              \
334 @@ -430,7 +441,7 @@ static int tracepoint_count;
335  
336  static struct cmd_list_element *breakpoint_set_cmdlist;
337  static struct cmd_list_element *breakpoint_show_cmdlist;
338 -static struct cmd_list_element *save_cmdlist;
339 +struct cmd_list_element *save_cmdlist;
340  
341  /* Return whether a breakpoint is an active enabled breakpoint.  */
342  static int
343 @@ -1252,6 +1263,22 @@ watchpoint_in_thread_scope (struct breakpoint *b)
344               && !is_executing (inferior_ptid)));
345  }
346  
347 +static void
348 +watchpoint_del_at_next_stop (struct breakpoint *b)
349 +{
350 +  gdb_assert (is_watchpoint (b));
351 +
352 +  if (b->related_breakpoint != b)
353 +    {
354 +      gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope);
355 +      gdb_assert (b->related_breakpoint->related_breakpoint == b);
356 +      b->related_breakpoint->disposition = disp_del_at_next_stop;
357 +      b->related_breakpoint->related_breakpoint = b->related_breakpoint;
358 +      b->related_breakpoint = b;
359 +    }
360 +  b->disposition = disp_del_at_next_stop;
361 +}
362 +
363  /* Assuming that B is a watchpoint:
364     - Reparse watchpoint expression, if REPARSE is non-zero
365     - Evaluate expression and store the result in B->val
366 @@ -1307,6 +1334,8 @@ update_watchpoint (struct breakpoint *b, int reparse)
367    struct frame_id saved_frame_id;
368    int frame_saved;
369  
370 +  gdb_assert (is_watchpoint (b));
371 +
372    /* If this is a local watchpoint, we only want to check if the
373       watchpoint frame is in scope if the current thread is the thread
374       that was used to create the watchpoint.  */
375 @@ -1510,13 +1539,7 @@ update_watchpoint (struct breakpoint *b, int reparse)
376  Watchpoint %d deleted because the program has left the block\n\
377  in which its expression is valid.\n"),
378                        b->number);
379 -      if (b->related_breakpoint)
380 -       {
381 -         b->related_breakpoint->disposition = disp_del_at_next_stop;
382 -         b->related_breakpoint->related_breakpoint = NULL;
383 -         b->related_breakpoint= NULL;
384 -       }
385 -      b->disposition = disp_del_at_next_stop;
386 +      watchpoint_del_at_next_stop (b);
387      }
388  
389    /* Restore the selected frame.  */
390 @@ -2201,6 +2224,33 @@ create_std_terminate_master_breakpoint (const char *func_name)
391    do_cleanups (old_chain);
392  }
393  
394 +/* Install a master breakpoint on the unwinder's debug hook.  */
395 +
396 +void
397 +create_exception_master_breakpoint (void)
398 +{
399 +  struct objfile *objfile;
400 +
401 +  ALL_OBJFILES (objfile)
402 +    {
403 +      struct minimal_symbol *debug_hook;
404 +
405 +      debug_hook = lookup_minimal_symbol_text ("_Unwind_DebugHook", objfile);
406 +      if (debug_hook != NULL)
407 +       {
408 +         struct breakpoint *b;
409 +
410 +         b = create_internal_breakpoint (get_objfile_arch (objfile),
411 +                                         SYMBOL_VALUE_ADDRESS (debug_hook),
412 +                                         bp_exception_master);
413 +         b->addr_string = xstrdup ("_Unwind_DebugHook");
414 +         b->enable_state = bp_disabled;
415 +       }
416 +    }
417 +
418 +  update_global_location_list (1);
419 +}
420 +
421  void
422  update_breakpoints_after_exec (void)
423  {
424 @@ -2242,7 +2292,8 @@ update_breakpoints_after_exec (void)
425      /* Thread event breakpoints must be set anew after an exec(),
426         as must overlay event and longjmp master breakpoints.  */
427      if (b->type == bp_thread_event || b->type == bp_overlay_event
428 -       || b->type == bp_longjmp_master || b->type == bp_std_terminate_master)
429 +       || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
430 +       || b->type == bp_exception_master)
431        {
432         delete_breakpoint (b);
433         continue;
434 @@ -2257,7 +2308,8 @@ update_breakpoints_after_exec (void)
435  
436      /* Longjmp and longjmp-resume breakpoints are also meaningless
437         after an exec.  */
438 -    if (b->type == bp_longjmp || b->type == bp_longjmp_resume)
439 +    if (b->type == bp_longjmp || b->type == bp_longjmp_resume
440 +       || b->type == bp_exception || b->type == bp_exception_resume)
441        {
442         delete_breakpoint (b);
443         continue;
444 @@ -2319,6 +2371,7 @@ update_breakpoints_after_exec (void)
445    create_longjmp_master_breakpoint ("siglongjmp");
446    create_longjmp_master_breakpoint ("_siglongjmp");
447    create_std_terminate_master_breakpoint ("std::terminate()");
448 +  create_exception_master_breakpoint ();
449  }
450  
451  int
452 @@ -2346,6 +2399,8 @@ detach_breakpoints (int pid)
453    /* Detach single-step breakpoints as well.  */
454    detach_single_step_breakpoints ();
455  
456 +  val |= target_detach_watchpoints ();
457 +
458    do_cleanups (old_chain);
459    return val;
460  }
461 @@ -2447,9 +2502,11 @@ remove_breakpoint_1 (struct bp_location *b, insertion_state_t is)
462         return val;
463        b->inserted = (is == mark_inserted);
464      }
465 -  else if (b->loc_type == bp_loc_hardware_watchpoint)
466 +  /* bp_loc_hardware_watchpoint with mark_inserted is being handled by
467 +     target_detach_watchpoints.  */
468 +  else if (b->loc_type == bp_loc_hardware_watchpoint && is == mark_uninserted)
469      {
470 -      b->inserted = (is == mark_inserted);
471 +      b->inserted = 0;
472        val = target_remove_watchpoint (b->address, b->length,
473                                       b->watchpoint_type, b->owner->cond_exp);
474  
475 @@ -3237,6 +3294,12 @@ print_it_typical (bpstat bs)
476        result = PRINT_NOTHING;
477        break;
478  
479 +    case bp_exception_master:
480 +      /* These should never be enabled.  */
481 +      printf_filtered (_("Exception Master Breakpoint: gdb should not stop!\n"));
482 +      result = PRINT_NOTHING;
483 +      break;
484 +
485      case bp_watchpoint:
486      case bp_hardware_watchpoint:
487        annotate_watchpoint (b->number);
488 @@ -3324,6 +3387,8 @@ print_it_typical (bpstat bs)
489      case bp_none:
490      case bp_longjmp:
491      case bp_longjmp_resume:
492 +    case bp_exception:
493 +    case bp_exception_resume:
494      case bp_step_resume:
495      case bp_watchpoint_scope:
496      case bp_call_dummy:
497 @@ -3331,6 +3396,8 @@ print_it_typical (bpstat bs)
498      case bp_tracepoint:
499      case bp_fast_tracepoint:
500      case bp_jit_event:
501 +    case bp_gnu_ifunc_resolver:
502 +    case bp_gnu_ifunc_resolver_return:
503      default:
504        result = PRINT_UNKNOWN;
505        break;
506 @@ -3549,6 +3616,8 @@ watchpoint_check (void *p)
507    gdb_assert (bs->breakpoint_at->owner != NULL);
508    b = bs->breakpoint_at->owner;
509  
510 +  gdb_assert (is_watchpoint (b));
511 +
512    /* If this is a local watchpoint, we only want to check if the
513       watchpoint frame is in scope if the current thread is the thread
514       that was used to create the watchpoint.  */
515 @@ -3655,13 +3724,7 @@ watchpoint_check (void *p)
516        ui_out_text (uiout, " deleted because the program has left the block in\n\
517  which its expression is valid.\n");     
518  
519 -      if (b->related_breakpoint)
520 -       {
521 -         b->related_breakpoint->disposition = disp_del_at_next_stop;
522 -         b->related_breakpoint->related_breakpoint = NULL;
523 -         b->related_breakpoint = NULL;
524 -       }
525 -      b->disposition = disp_del_at_next_stop;
526 +      watchpoint_del_at_next_stop (b);
527  
528        return WP_DELETED;
529      }
530 @@ -3730,8 +3793,12 @@ bpstat_check_location (const struct bp_location *bl,
531  
532  /* If BS refers to a watchpoint, determine if the watched values
533     has actually changed, and we should stop.  If not, set BS->stop
534 -   to 0.  */
535 -static void
536 +   to 0.
537 +   Return 0 for watchpoints which could not be the cause of this trap.
538 +   In such case PRINT_IT will be print_it_noop and STOP will be 0.
539 +   Otherwise return 1 but in such case it is not guaranteed whether this
540 +   breakpoint did or did not trigger this trap.  */
541 +static int
542  bpstat_check_watchpoint (bpstat bs)
543  {
544    const struct bp_location *bl;
545 @@ -3865,9 +3932,7 @@ bpstat_check_watchpoint (bpstat bs)
546             case 0:
547               /* Error from catch_errors.  */
548               printf_filtered (_("Watchpoint %d deleted.\n"), b->number);
549 -             if (b->related_breakpoint)
550 -               b->related_breakpoint->disposition = disp_del_at_next_stop;
551 -             b->disposition = disp_del_at_next_stop;
552 +             watchpoint_del_at_next_stop (b);
553               /* We've already printed what needs to be printed.  */
554               bs->print_it = print_it_done;
555               break;
556 @@ -3881,8 +3946,10 @@ bpstat_check_watchpoint (bpstat bs)
557              anything for this watchpoint.  */
558           bs->print_it = print_it_noop;
559           bs->stop = 0;
560 +         return 0;
561         }
562      }
563 +  return 1;
564  }
565  
566  
567 @@ -3914,7 +3981,7 @@ bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
568          watchpoint as triggered so that we will handle the
569          out-of-scope event.  We'll get to the watchpoint next
570          iteration.  */
571 -      if (b->type == bp_watchpoint_scope)
572 +      if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
573         b->related_breakpoint->watchpoint_triggered = watch_triggered_yes;
574  
575        if (is_watchpoint (b))
576 @@ -4045,6 +4112,8 @@ bpstat_stop_status (struct address_space *aspace,
577  
578        for (bl = b->loc; bl != NULL; bl = bl->next)
579         {
580 +         bpstat bs_prev = bs;
581 +
582           /* For hardware watchpoints, we look only at the first location.
583              The watchpoint_check function will work on the entire expression,
584              not the individual locations.  For read watchpoints, the
585 @@ -4062,6 +4131,7 @@ bpstat_stop_status (struct address_space *aspace,
586           /* Come here if it's a watchpoint, or if the break address matches */
587  
588           bs = bpstat_alloc (bl, bs);   /* Alloc a bpstat to explain stop */
589 +         gdb_assert (bs_prev->next == bs);
590  
591           /* Assume we stop.  Should we find watchpoint that is not actually
592              triggered, or if condition of breakpoint is false, we'll reset
593 @@ -4069,13 +4139,23 @@ bpstat_stop_status (struct address_space *aspace,
594           bs->stop = 1;
595           bs->print = 1;
596  
597 -         bpstat_check_watchpoint (bs);
598 -         if (!bs->stop)
599 -           continue;
600 +         if (!bpstat_check_watchpoint (bs))
601 +           {
602 +             /* Ensure bpstat_explains_signal stays false if this BL could not be
603 +                the cause of this trap.  */
604 +
605 +             gdb_assert (bs->print_it == print_it_noop);
606 +             gdb_assert (!bs->stop);
607 +             xfree (bs);
608 +             bs = bs_prev;
609 +             bs->next = NULL;
610 +             continue;
611 +           }
612  
613           if (b->type == bp_thread_event || b->type == bp_overlay_event
614               || b->type == bp_longjmp_master
615 -             || b->type == bp_std_terminate_master)
616 +             || b->type == bp_std_terminate_master
617 +             || b->type == bp_exception_master)
618             /* We do not stop for these.  */
619             bs->stop = 0;
620           else
621 @@ -4176,7 +4256,7 @@ handle_jit_event (void)
622  /* Decide what infrun needs to do with this bpstat.  */
623  
624  struct bpstat_what
625 -bpstat_what (bpstat bs)
626 +bpstat_what (bpstat bs_head)
627  {
628    struct bpstat_what retval;
629    /* We need to defer calling `solib_add', as adding new symbols
630 @@ -4184,11 +4264,13 @@ bpstat_what (bpstat bs)
631       and hence may clear unprocessed entries in the BS chain.  */
632    int shlib_event = 0;
633    int jit_event = 0;
634 +  bpstat bs;
635  
636    retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
637    retval.call_dummy = STOP_NONE;
638 +  retval.is_longjmp = 0;
639  
640 -  for (; bs != NULL; bs = bs->next)
641 +  for (bs = bs_head; bs != NULL; bs = bs->next)
642      {
643        /* Extract this BS's action.  After processing each BS, we check
644          if its action overrides all we've seem so far.  */
645 @@ -4242,10 +4324,15 @@ bpstat_what (bpstat bs)
646             }
647           break;
648         case bp_longjmp:
649 +       case bp_exception:
650           this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
651 +         retval.is_longjmp = bs->breakpoint_at->owner->type == bp_longjmp;
652           break;
653         case bp_longjmp_resume:
654 +       case bp_exception_resume:
655           this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
656 +         retval.is_longjmp
657 +           = bs->breakpoint_at->owner->type == bp_longjmp_resume;
658           break;
659         case bp_step_resume:
660           if (bs->stop)
661 @@ -4261,6 +4348,7 @@ bpstat_what (bpstat bs)
662         case bp_overlay_event:
663         case bp_longjmp_master:
664         case bp_std_terminate_master:
665 +       case bp_exception_master:
666           this_action = BPSTAT_WHAT_SINGLE;
667           break;
668         case bp_catchpoint:
669 @@ -4313,6 +4401,20 @@ bpstat_what (bpstat bs)
670              out already.  */
671           internal_error (__FILE__, __LINE__,
672                           _("bpstat_what: tracepoint encountered"));
673 +         break;
674 +       case bp_gnu_ifunc_resolver:
675 +         /* Skip the current breakpoint but otherwise nothing happens.  GDB is
676 +            inserting new bp_gnu_ifunc_resolver_return at this point but
677 +            bp_gnu_ifunc_resolver is being kept there as another
678 +            bp_gnu_ifunc_resolver_return may be inserted in the meantime.  */
679 +         this_action = BPSTAT_WHAT_SINGLE;
680 +         break;
681 +       case bp_gnu_ifunc_resolver_return:
682 +         /* The whole bp_gnu_ifunc_resolver with its associated
683 +            bp_gnu_ifunc_resolver_return related_breakpoint's has been
684 +            resolved now, all these helper breakpoints are being removed and
685 +            new final bp_breakpoint is being put at the target location.  */
686 +         break;
687         default:
688           internal_error (__FILE__, __LINE__,
689                           _("bpstat_what: unhandled bptype %d"), (int) bptype);
690 @@ -4350,6 +4452,23 @@ bpstat_what (bpstat bs)
691        handle_jit_event ();
692      }
693  
694 +  for (bs = bs_head; bs != NULL; bs = bs->next)
695 +    {
696 +      if (bs->breakpoint_at == NULL)
697 +       continue;
698 +      if (bs->breakpoint_at->owner == NULL)
699 +       continue;
700 +      switch (bs->breakpoint_at->owner->type)
701 +       {
702 +       case bp_gnu_ifunc_resolver:
703 +         gnu_ifunc_resolver_stop (bs->breakpoint_at->owner);
704 +         break;
705 +       case bp_gnu_ifunc_resolver_return:
706 +         gnu_ifunc_resolver_return_stop (bs->breakpoint_at->owner);
707 +         break;
708 +       }
709 +    }
710 +
711    return retval;
712  }
713  
714 @@ -4461,6 +4580,8 @@ print_one_breakpoint_location (struct breakpoint *b,
715      {bp_access_watchpoint, "acc watchpoint"},
716      {bp_longjmp, "longjmp"},
717      {bp_longjmp_resume, "longjmp resume"},
718 +    {bp_exception, "exception"},
719 +    {bp_exception_resume, "exception resume"},
720      {bp_step_resume, "step resume"},
721      {bp_watchpoint_scope, "watchpoint scope"},
722      {bp_call_dummy, "call dummy"},
723 @@ -4470,11 +4591,14 @@ print_one_breakpoint_location (struct breakpoint *b,
724      {bp_overlay_event, "overlay events"},
725      {bp_longjmp_master, "longjmp master"},
726      {bp_std_terminate_master, "std::terminate master"},
727 +    {bp_exception_master, "exception master"},
728      {bp_catchpoint, "catchpoint"},
729      {bp_tracepoint, "tracepoint"},
730      {bp_fast_tracepoint, "fast tracepoint"},
731      {bp_static_tracepoint, "static tracepoint"},
732      {bp_jit_event, "jit events"},
733 +    {bp_gnu_ifunc_resolver, "gnu-ifunc resolver"},
734 +    {bp_gnu_ifunc_resolver_return, "gnu-func resolver return"},
735    };
736    
737    static char bpenables[] = "nynny";
738 @@ -4595,6 +4719,8 @@ print_one_breakpoint_location (struct breakpoint *b,
739        case bp_finish:
740        case bp_longjmp:
741        case bp_longjmp_resume:
742 +      case bp_exception:
743 +      case bp_exception_resume:
744        case bp_step_resume:
745        case bp_watchpoint_scope:
746        case bp_call_dummy:
747 @@ -4604,10 +4730,13 @@ print_one_breakpoint_location (struct breakpoint *b,
748        case bp_overlay_event:
749        case bp_longjmp_master:
750        case bp_std_terminate_master:
751 +      case bp_exception_master:
752        case bp_tracepoint:
753        case bp_fast_tracepoint:
754        case bp_static_tracepoint:
755        case bp_jit_event:
756 +      case bp_gnu_ifunc_resolver:
757 +      case bp_gnu_ifunc_resolver_return:
758         if (opts.addressprint)
759           {
760             annotate_field (4);
761 @@ -4888,7 +5017,8 @@ user_settable_breakpoint (const struct breakpoint *b)
762           || b->type == bp_catchpoint
763           || b->type == bp_hardware_breakpoint
764           || is_tracepoint (b)
765 -         || is_watchpoint (b));
766 +         || is_watchpoint (b)
767 +         || b->type == bp_gnu_ifunc_resolver);
768  }
769         
770  /* Print information on user settable breakpoint (watchpoint, etc)
771 @@ -5334,6 +5464,8 @@ allocate_bp_location (struct breakpoint *bpt)
772      case bp_finish:
773      case bp_longjmp:
774      case bp_longjmp_resume:
775 +    case bp_exception:
776 +    case bp_exception_resume:
777      case bp_step_resume:
778      case bp_watchpoint_scope:
779      case bp_call_dummy:
780 @@ -5344,6 +5476,9 @@ allocate_bp_location (struct breakpoint *bpt)
781      case bp_jit_event:
782      case bp_longjmp_master:
783      case bp_std_terminate_master:
784 +    case bp_gnu_ifunc_resolver:
785 +    case bp_gnu_ifunc_resolver_return:
786 +    case bp_exception_master:
787        loc->loc_type = bp_loc_software_breakpoint;
788        break;
789      case bp_hardware_breakpoint:
790 @@ -5420,6 +5555,7 @@ set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
791    b->syscalls_to_be_caught = NULL;
792    b->ops = NULL;
793    b->condition_not_parsed = 0;
794 +  b->related_breakpoint = b;
795  
796    /* Add this breakpoint to the end of the chain
797       so that a list of breakpoints will come out in order
798 @@ -5439,7 +5575,7 @@ set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
799  
800  /* Initialize loc->function_name.  */
801  static void
802 -set_breakpoint_location_function (struct bp_location *loc)
803 +set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
804  {
805    gdb_assert (loc->owner != NULL);
806  
807 @@ -5447,8 +5583,29 @@ set_breakpoint_location_function (struct bp_location *loc)
808        || loc->owner->type == bp_hardware_breakpoint
809        || is_tracepoint (loc->owner))
810      {
811 -      find_pc_partial_function (loc->address, &(loc->function_name), 
812 -                               NULL, NULL);
813 +      if (find_pc_partial_function (loc->address, &(loc->function_name), NULL,
814 +                                   NULL) == FIND_PC_PARTIAL_FUNCTION_GNU_IFUNC
815 +         && !explicit_loc)
816 +       {
817 +         struct breakpoint *b = loc->owner;
818 +
819 +         gdb_assert (loc->pspace == current_program_space);
820 +         if (resolve_gnu_ifunc (loc->function_name, &loc->requested_address))
821 +           {
822 +             /* Recalculate ADDRESS based on new REQUESTED_ADDRESS.  */
823 +             loc->address = adjust_breakpoint_address (loc->gdbarch,
824 +                                                       loc->requested_address,
825 +                                                       b->type);
826 +           }
827 +         else if (b->type == bp_breakpoint && b->loc == loc
828 +                  && loc->next == NULL && b->related_breakpoint == b)
829 +           {
830 +             /* Create only the whole new breakpoint of this type but do not
831 +                mess more complicated breakpoints with multiple locations.  */
832 +             b->type = bp_gnu_ifunc_resolver;
833 +           }
834 +       }
835 +
836        if (loc->function_name)
837         loc->function_name = xstrdup (loc->function_name);
838      }
839 @@ -5521,7 +5678,8 @@ set_raw_breakpoint (struct gdbarch *gdbarch,
840    b->loc->section = sal.section;
841    b->line_number = sal.line;
842  
843 -  set_breakpoint_location_function (b->loc);
844 +  set_breakpoint_location_function (b->loc,
845 +                                   sal.explicit_pc || sal.explicit_line);
846  
847    breakpoints_changed ();
848  
849 @@ -5548,8 +5706,7 @@ make_breakpoint_permanent (struct breakpoint *b)
850  }
851  
852  /* Call this routine when stepping and nexting to enable a breakpoint
853 -   if we do a longjmp() in THREAD.  When we hit that breakpoint, call
854 -   set_longjmp_resume_breakpoint() to figure out where we are going. */
855 +   if we do a longjmp() or 'throw' in THREAD.  */
856  
857  void
858  set_longjmp_breakpoint (int thread)
859 @@ -5562,11 +5719,12 @@ set_longjmp_breakpoint (int thread)
860       clones of those and enable them for the requested thread.  */
861    ALL_BREAKPOINTS_SAFE (b, temp)
862      if (b->pspace == current_program_space
863 -       && b->type == bp_longjmp_master)
864 +       && (b->type == bp_longjmp_master
865 +           || b->type == bp_exception_master))
866        {
867         struct breakpoint *clone = clone_momentary_breakpoint (b);
868  
869 -       clone->type = bp_longjmp;
870 +       clone->type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
871         clone->thread = thread;
872        }
873  }
874 @@ -5578,7 +5736,7 @@ delete_longjmp_breakpoint (int thread)
875    struct breakpoint *b, *temp;
876  
877    ALL_BREAKPOINTS_SAFE (b, temp)
878 -    if (b->type == bp_longjmp)
879 +    if (b->type == bp_longjmp || b->type == bp_exception)
880        {
881         if (b->thread == thread)
882           delete_breakpoint (b);
883 @@ -6595,7 +6753,7 @@ clone_momentary_breakpoint (struct breakpoint *orig)
884  
885    copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type);
886    copy->loc = allocate_bp_location (copy);
887 -  set_breakpoint_location_function (copy->loc);
888 +  set_breakpoint_location_function (copy->loc, 1);
889  
890    copy->loc->gdbarch = orig->loc->gdbarch;
891    copy->loc->requested_address = orig->loc->requested_address;
892 @@ -6694,6 +6852,7 @@ mention (struct breakpoint *b)
893         do_cleanups (ui_out_chain);
894         break;
895        case bp_breakpoint:
896 +      case bp_gnu_ifunc_resolver:
897         if (ui_out_is_mi_like_p (uiout))
898           {
899             say_where = 0;
900 @@ -6704,6 +6863,8 @@ mention (struct breakpoint *b)
901         else
902           printf_filtered (_("Breakpoint"));
903         printf_filtered (_(" %d"), b->number);
904 +       if (b->type == bp_gnu_ifunc_resolver)
905 +         printf_filtered (_(" at gnu-indirect-function resolver"));
906         say_where = 1;
907         break;
908        case bp_hardware_breakpoint:
909 @@ -6750,6 +6911,8 @@ mention (struct breakpoint *b)
910        case bp_finish:
911        case bp_longjmp:
912        case bp_longjmp_resume:
913 +      case bp_exception:
914 +      case bp_exception_resume:
915        case bp_step_resume:
916        case bp_call_dummy:
917        case bp_std_terminate:
918 @@ -6760,6 +6923,8 @@ mention (struct breakpoint *b)
919        case bp_jit_event:
920        case bp_longjmp_master:
921        case bp_std_terminate_master:
922 +      case bp_gnu_ifunc_resolver_return:
923 +      case bp_exception_master:
924         break;
925        }
926  
927 @@ -6820,7 +6985,8 @@ add_location_to_breakpoint (struct breakpoint *b,
928    gdb_assert (loc->pspace != NULL);
929    loc->section = sal->section;
930  
931 -  set_breakpoint_location_function (loc);
932 +  set_breakpoint_location_function (loc,
933 +                                   sal->explicit_pc || sal->explicit_line);
934    return loc;
935  }
936  \f
937 @@ -8346,6 +8512,7 @@ struct until_break_command_continuation_args
938  {
939    struct breakpoint *breakpoint;
940    struct breakpoint *breakpoint2;
941 +  int thread_num;
942  };
943  
944  /* This function is called by fetch_inferior_event via the
945 @@ -8360,6 +8527,7 @@ until_break_command_continuation (void *arg)
946    delete_breakpoint (a->breakpoint);
947    if (a->breakpoint2)
948      delete_breakpoint (a->breakpoint2);
949 +  delete_longjmp_breakpoint (a->thread_num);
950  }
951  
952  void
953 @@ -8371,6 +8539,8 @@ until_break_command (char *arg, int from_tty, int anywhere)
954    struct breakpoint *breakpoint;
955    struct breakpoint *breakpoint2 = NULL;
956    struct cleanup *old_chain;
957 +  int thread;
958 +  struct thread_info *tp;
959  
960    clear_proceed_status ();
961  
962 @@ -8409,6 +8579,9 @@ until_break_command (char *arg, int from_tty, int anywhere)
963  
964    old_chain = make_cleanup_delete_breakpoint (breakpoint);
965  
966 +  tp = inferior_thread ();
967 +  thread = tp->num;
968 +
969    /* Keep within the current frame, or in frames called by the current
970       one.  */
971  
972 @@ -8421,6 +8594,10 @@ until_break_command (char *arg, int from_tty, int anywhere)
973                                               frame_unwind_caller_id (frame),
974                                               bp_until);
975        make_cleanup_delete_breakpoint (breakpoint2);
976 +
977 +      set_longjmp_breakpoint (thread);
978 +      tp->initiating_frame = frame_unwind_caller_id (frame);
979 +      make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
980      }
981  
982    proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
983 @@ -8437,6 +8614,7 @@ until_break_command (char *arg, int from_tty, int anywhere)
984  
985        args->breakpoint = breakpoint;
986        args->breakpoint2 = breakpoint2;
987 +      args->thread_num = thread;
988  
989        discard_cleanups (old_chain);
990        add_continuation (inferior_thread (),
991 @@ -9564,12 +9742,22 @@ delete_breakpoint (struct breakpoint *bpt)
992  
993    /* At least avoid this stale reference until the reference counting of
994       breakpoints gets resolved.  */
995 -  if (bpt->related_breakpoint != NULL)
996 +  if (bpt->related_breakpoint != bpt)
997      {
998 -      gdb_assert (bpt->related_breakpoint->related_breakpoint == bpt);
999 -      bpt->related_breakpoint->disposition = disp_del_at_next_stop;
1000 -      bpt->related_breakpoint->related_breakpoint = NULL;
1001 -      bpt->related_breakpoint = NULL;
1002 +      if (bpt->type == bp_watchpoint_scope)
1003 +       watchpoint_del_at_next_stop (bpt->related_breakpoint);
1004 +      else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
1005 +       watchpoint_del_at_next_stop (bpt);
1006 +      else
1007 +       {
1008 +         struct breakpoint *related;
1009 +
1010 +         /* Unlink bpt from the bpt->related_breakpoint ring.  */
1011 +         for (related = bpt; related->related_breakpoint != bpt;
1012 +              related = related->related_breakpoint);
1013 +         related->related_breakpoint = bpt->related_breakpoint;
1014 +         bpt->related_breakpoint = bpt;
1015 +       }
1016      }
1017  
1018    observer_notify_breakpoint_deleted (bpt->number);
1019 @@ -9658,6 +9846,7 @@ delete_command (char *arg, int from_tty)
1020             && b->type != bp_overlay_event
1021             && b->type != bp_longjmp_master
1022             && b->type != bp_std_terminate_master
1023 +           && b->type != bp_exception_master
1024             && b->number >= 0)
1025           {
1026             breaks_to_delete = 1;
1027 @@ -9679,6 +9868,7 @@ delete_command (char *arg, int from_tty)
1028                 && b->type != bp_overlay_event
1029                 && b->type != bp_longjmp_master
1030                 && b->type != bp_std_terminate_master
1031 +               && b->type != bp_exception_master
1032                 && b->number >= 0)
1033               delete_breakpoint (b);
1034           }
1035 @@ -9887,6 +10077,9 @@ update_breakpoint_locations (struct breakpoint *b,
1036      return;
1037  
1038    b->loc = NULL;
1039 +  xfree (b->source_file);
1040 +  b->source_file = NULL;
1041 +  b->line_number = 0;
1042  
1043    for (i = 0; i < sals.nelts; ++i)
1044      {
1045 @@ -9913,11 +10106,7 @@ update_breakpoint_locations (struct breakpoint *b,
1046             }
1047         }
1048  
1049 -      if (b->source_file != NULL)
1050 -       xfree (b->source_file);
1051 -      if (sals.sals[i].symtab == NULL)
1052 -       b->source_file = NULL;
1053 -      else
1054 +      if (sals.sals[i].symtab != NULL && b->source_file == NULL)
1055         b->source_file = xstrdup (sals.sals[i].symtab->filename);
1056  
1057        if (b->line_number == 0)
1058 @@ -9999,6 +10188,7 @@ breakpoint_re_set_one (void *bint)
1059      case bp_tracepoint:
1060      case bp_fast_tracepoint:
1061      case bp_static_tracepoint:
1062 +    case bp_gnu_ifunc_resolver:
1063        /* Do not attempt to re-set breakpoints disabled during startup.  */
1064        if (b->enable_state == bp_startup_disabled)
1065         return 0;
1066 @@ -10139,6 +10329,7 @@ breakpoint_re_set_one (void *bint)
1067      case bp_overlay_event:
1068      case bp_longjmp_master:
1069      case bp_std_terminate_master:
1070 +    case bp_exception_master:
1071        delete_breakpoint (b);
1072        break;
1073  
1074 @@ -10162,7 +10353,10 @@ breakpoint_re_set_one (void *bint)
1075      case bp_step_resume:
1076      case bp_longjmp:
1077      case bp_longjmp_resume:
1078 +    case bp_exception:
1079 +    case bp_exception_resume:
1080      case bp_jit_event:
1081 +    case bp_gnu_ifunc_resolver_return:
1082        break;
1083      }
1084  
1085 @@ -10205,6 +10399,7 @@ breakpoint_re_set (void)
1086    create_longjmp_master_breakpoint ("siglongjmp");
1087    create_longjmp_master_breakpoint ("_siglongjmp");
1088    create_std_terminate_master_breakpoint ("std::terminate()");
1089 +  create_exception_master_breakpoint ();
1090  }
1091  \f
1092  /* Reset the thread number of this breakpoint:
1093 @@ -10334,11 +10529,20 @@ map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
1094           ALL_BREAKPOINTS_SAFE (b, tmp)
1095             if (b->number == num)
1096               {
1097 -               struct breakpoint *related_breakpoint = b->related_breakpoint;
1098 +               struct breakpoint *related_breakpoint;
1099 +
1100                 match = 1;
1101 -               function (b, data);
1102 -               if (related_breakpoint)
1103 -                 function (related_breakpoint, data);
1104 +               related_breakpoint = b;
1105 +               do
1106 +                 {
1107 +                   struct breakpoint *next_related_b;
1108 +
1109 +                   /* FUNCTION can be also delete_breakpoint.  */
1110 +                   next_related_b = related_breakpoint->related_breakpoint;
1111 +                   function (related_breakpoint, data);
1112 +                   related_breakpoint = next_related_b;
1113 +                 }
1114 +               while (related_breakpoint != b);
1115                 break;
1116               }
1117           if (match == 0)
1118 @@ -11428,6 +11632,22 @@ all_tracepoints ()
1119    return tp_vec;
1120  }
1121  
1122 +/* Call type_mark_used for any TYPEs referenced from this GDB source file.  */
1123 +
1124 +static void
1125 +breakpoint_types_mark_used (void)
1126 +{
1127 +  struct breakpoint *b;
1128 +
1129 +  ALL_BREAKPOINTS (b)
1130 +    {
1131 +      if (b->exp)
1132 +       exp_types_mark_used (b->exp);
1133 +      if (b->val)
1134 +       type_mark_used (value_type (b->val));
1135 +    }
1136 +}
1137 +
1138  \f
1139  /* This help string is used for the break, hbreak, tbreak and thbreak commands.
1140     It is defined as a macro to prevent duplication.
1141 @@ -11497,6 +11717,107 @@ save_command (char *arg, int from_tty)
1142    help_list (save_cmdlist, "save ", -1, gdb_stdout);
1143  }
1144  
1145 +static void
1146 +gnu_ifunc_resolver_stop (struct breakpoint *b)
1147 +{
1148 +  struct breakpoint *b_return;
1149 +  struct frame_info *prev_frame = get_prev_frame (get_current_frame ());
1150 +  struct frame_id prev_frame_id = get_stack_frame_id (prev_frame);
1151 +  CORE_ADDR prev_pc = get_frame_pc (prev_frame);
1152 +  int thread_id = pid_to_thread_id (inferior_ptid);
1153 +
1154 +  gdb_assert (b->type == bp_gnu_ifunc_resolver);
1155 +
1156 +  for (b_return = b->related_breakpoint; b_return != b;
1157 +       b_return = b_return->related_breakpoint)
1158 +    {
1159 +      gdb_assert (b_return->type == bp_gnu_ifunc_resolver_return);
1160 +      gdb_assert (b_return->loc != NULL && b_return->loc->next == NULL);
1161 +      gdb_assert (frame_id_p (b_return->frame_id));
1162 +
1163 +      if (b_return->thread == thread_id
1164 +         && b_return->loc->requested_address == prev_pc
1165 +         && frame_id_eq (b_return->frame_id, prev_frame_id))
1166 +       break;
1167 +    }
1168 +
1169 +  if (b_return == b)
1170 +    {
1171 +      struct symtab_and_line sal;
1172 +
1173 +      /* No need to call find_pc_line for symbols resolving as this is only
1174 +        a helper breakpointer never shown to the user.  */
1175 +
1176 +      init_sal (&sal);
1177 +      sal.pspace = current_inferior ()->pspace;
1178 +      sal.pc = prev_pc;
1179 +      sal.section = find_pc_overlay (sal.pc);
1180 +      sal.explicit_pc = 1;
1181 +      b_return = set_momentary_breakpoint (get_frame_arch (prev_frame), sal,
1182 +                                          prev_frame_id,
1183 +                                          bp_gnu_ifunc_resolver_return);
1184 +
1185 +      /* Add new b_return to the ring list b->related_breakpoint.  */
1186 +      gdb_assert (b_return->related_breakpoint == b_return);
1187 +      b_return->related_breakpoint = b->related_breakpoint;
1188 +      b->related_breakpoint = b_return;
1189 +    }
1190 +}
1191 +
1192 +static void
1193 +gnu_ifunc_resolver_return_stop (struct breakpoint *b)
1194 +{
1195 +  struct gdbarch *gdbarch = get_frame_arch (get_current_frame ());
1196 +  struct type *func_func_type = builtin_type (gdbarch)->builtin_func_func;
1197 +  struct type *value_type = TYPE_TARGET_TYPE (func_func_type);
1198 +  struct regcache *regcache = get_thread_regcache (inferior_ptid);
1199 +  struct value *value;
1200 +  CORE_ADDR resolved_address, resolved_pc;
1201 +  struct symtab_and_line sal;
1202 +  struct symtabs_and_lines sals;
1203 +
1204 +  gdb_assert (b->type == bp_gnu_ifunc_resolver_return);
1205 +
1206 +  value = allocate_value (value_type);
1207 +  gdbarch_return_value (gdbarch, func_func_type, value_type, regcache,
1208 +                       value_contents_raw (value), NULL);
1209 +  resolved_address = value_as_address (value);
1210 +  resolved_pc = gdbarch_convert_from_func_ptr_addr (gdbarch,
1211 +                                                   resolved_address,
1212 +                                                   &current_target);
1213 +
1214 +  while (b->related_breakpoint != b)
1215 +    {
1216 +      struct breakpoint *b_next = b->related_breakpoint;
1217 +
1218 +      switch (b->type)
1219 +       {
1220 +       case bp_gnu_ifunc_resolver:
1221 +         break;
1222 +       case bp_gnu_ifunc_resolver_return:
1223 +         delete_breakpoint (b);
1224 +         break;
1225 +       default:
1226 +         internal_error (__FILE__, __LINE__,
1227 +                         _("handle_inferior_event: Invalid "
1228 +                           "gnu-indirect-function breakpoint type %d"),
1229 +                         (int) b->type);
1230 +       }
1231 +      b = b_next;
1232 +    }
1233 +  gdb_assert (b->type == bp_gnu_ifunc_resolver);
1234 +
1235 +  gdb_assert (current_program_space == b->pspace);
1236 +  gnu_ifunc_record_cache (gdbarch, b->addr_string, resolved_pc);
1237 +
1238 +  sal = find_pc_line (resolved_pc, 0);
1239 +  sals.nelts = 1;
1240 +  sals.sals = &sal;
1241 +
1242 +  b->type = bp_breakpoint;
1243 +  update_breakpoint_locations (b, sals);
1244 +}
1245 +
1246  void
1247  _initialize_breakpoint (void)
1248  {
1249 @@ -12022,4 +12343,5 @@ inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
1250    automatic_hardware_breakpoints = 1;
1251  
1252    observer_attach_about_to_proceed (breakpoint_about_to_proceed);
1253 +  observer_attach_mark_used (breakpoint_types_mark_used);
1254  }
1255 diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
1256 index 6f5d050..d0c3cc1 100644
1257 --- a/gdb/breakpoint.h
1258 +++ b/gdb/breakpoint.h
1259 @@ -56,6 +56,13 @@ enum bptype
1260      bp_longjmp,                        /* secret breakpoint to find longjmp() */
1261      bp_longjmp_resume,         /* secret breakpoint to escape longjmp() */
1262  
1263 +    /* An internal breakpoint that is installed on the unwinder's
1264 +       debug hook.  */
1265 +    bp_exception,
1266 +    /* An internal breakpoint that is set at the point where an
1267 +       exception will land.  */
1268 +    bp_exception_resume,
1269 +
1270      /* Used by wait_for_inferior for stepping over subroutine calls, for
1271         stepping over signal handlers, and for skipping prologues.  */
1272      bp_step_resume,
1273 @@ -125,6 +132,9 @@ enum bptype
1274      /* Master copies of std::terminate breakpoints.  */
1275      bp_std_terminate_master,
1276  
1277 +    /* Like bp_longjmp_master, but for exceptions.  */
1278 +    bp_exception_master,
1279 +
1280      bp_catchpoint,
1281  
1282      bp_tracepoint,
1283 @@ -133,6 +143,9 @@ enum bptype
1284  
1285      /* Event for JIT compiled code generation or deletion.  */
1286      bp_jit_event,
1287 +
1288 +    bp_gnu_ifunc_resolver,
1289 +    bp_gnu_ifunc_resolver_return,
1290    };
1291  
1292  /* States of enablement of breakpoint. */
1293 @@ -653,6 +666,10 @@ struct bpstat_what
1294         continuing from a call dummy without popping the frame is not a
1295         useful one).  */
1296      enum stop_stack_kind call_dummy;
1297 +
1298 +    /* Used for BPSTAT_WHAT_SET_LONGJMP_RESUME.  True if we are
1299 +       handling a longjmp, false if we are handling an exception.  */
1300 +    int is_longjmp;
1301    };
1302  
1303  /* The possible return values for print_bpstat, print_it_normal,
1304 diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
1305 index 926ae2f..a59b965 100644
1306 --- a/gdb/c-typeprint.c
1307 +++ b/gdb/c-typeprint.c
1308 @@ -585,7 +585,13 @@ c_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
1309         fprintf_filtered (stream, ")");
1310  
1311        fprintf_filtered (stream, "[");
1312 -      if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
1313 +      if (TYPE_RANGE_DATA (TYPE_INDEX_TYPE (type))->high.kind
1314 +         != RANGE_BOUND_KIND_CONSTANT)
1315 +       {
1316 +         /* No _() - printed sources should not be locale dependent.  */
1317 +         fprintf_filtered (stream, "variable");
1318 +       }
1319 +      else if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
1320         && !TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
1321         fprintf_filtered (stream, "%d",
1322                           (TYPE_LENGTH (type)
1323 diff --git a/gdb/config.in b/gdb/config.in
1324 index 1fc457d..f4c846a 100644
1325 --- a/gdb/config.in
1326 +++ b/gdb/config.in
1327 @@ -50,11 +50,10 @@
1328     language is requested. */
1329  #undef ENABLE_NLS
1330  
1331 -/* look for global separate data files in this path [DATADIR/gdb] */
1332 +/* Global directory for GDB data files. */
1333  #undef GDB_DATADIR
1334  
1335 -/* Define if the gdb-datadir directory should be relocated when GDB is moved.
1336 -   */
1337 +/* Define if GDB datadir should be relocated when GDB is moved. */
1338  #undef GDB_DATADIR_RELOCATABLE
1339  
1340  /* Define to be a string naming the default host character set. */
1341 @@ -769,6 +768,9 @@
1342     'ptrdiff_t'. */
1343  #undef PTRDIFF_T_SUFFIX
1344  
1345 +/* Define to install path for Python sources */
1346 +#undef PYTHONDIR
1347 +
1348  /* Define if the python directory should be relocated when GDB is moved. */
1349  #undef PYTHON_PATH_RELOCATABLE
1350  
1351 diff --git a/gdb/configure b/gdb/configure
1352 index 041ffc1..8243abb 100755
1353 --- a/gdb/configure
1354 +++ b/gdb/configure
1355 @@ -679,6 +679,8 @@ REPORT_BUGS_TO
1356  PKGVERSION
1357  TARGET_OBS
1358  subdirs
1359 +pythondir
1360 +GDB_DATADIR_PATH
1361  GDB_DATADIR
1362  DEBUGDIR
1363  am__fastdepCC_FALSE
1364 @@ -945,6 +947,7 @@ enable_dependency_tracking
1365  with_separate_debug_dir
1366  with_gdb_datadir
1367  with_relocated_sources
1368 +with_pythondir
1369  enable_targets
1370  enable_64_bit_bfd
1371  enable_gdbcli
1372 @@ -1646,6 +1649,10 @@ Optional Packages:
1373                            [DATADIR/gdb]
1374    --with-relocated-sources=PATH
1375                            automatically relocate this path for source files
1376 +  --with-gdb-datadir      look for global separate data files in this path
1377 +                          [DATADIR/gdb]
1378 +  --with-pythondir        install Python data files in this path
1379 +                          [DATADIR/gdb/python]
1380    --with-libunwind        use libunwind frame unwinding support
1381    --with-curses           use the curses library instead of the termcap
1382                            library
1383 @@ -7878,6 +7885,73 @@ _ACEOF
1384  fi
1385  
1386  
1387 +# GDB's datadir relocation
1388 +
1389 +gdbdatadir=${datadir}/gdb
1390 +
1391 +
1392 +# Check whether --with-gdb-datadir was given.
1393 +if test "${with_gdb_datadir+set}" = set; then :
1394 +  withval=$with_gdb_datadir; gdbdatadir="${withval}"
1395 +fi
1396 +
1397 +
1398 +
1399 +  test "x$prefix" = xNONE && prefix="$ac_default_prefix"
1400 +  test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
1401 +  ac_define_dir=`eval echo $gdbdatadir`
1402 +  ac_define_dir=`eval echo $ac_define_dir`
1403 +
1404 +cat >>confdefs.h <<_ACEOF
1405 +#define GDB_DATADIR "$ac_define_dir"
1406 +_ACEOF
1407 +
1408 +
1409 +
1410 +if test "x$exec_prefix" = xNONE || test "x$exec_prefix" = 'x${prefix}'; then
1411 +  if test "x$prefix" = xNONE; then
1412 +    test_prefix=/usr/local
1413 +  else
1414 +    test_prefix=$prefix
1415 +  fi
1416 +else
1417 +  test_prefix=$exec_prefix
1418 +fi
1419 +
1420 +case ${gdbdatadir} in
1421 +  "${test_prefix}"|"${test_prefix}/"*|\
1422 +  '${exec_prefix}'|'${exec_prefix}/'*)
1423 +
1424 +$as_echo "#define GDB_DATADIR_RELOCATABLE 1" >>confdefs.h
1425 +
1426 +  ;;
1427 +esac
1428 +GDB_DATADIR_PATH=${gdbdatadir}
1429 +
1430 +
1431 +
1432 +# Check whether --with-pythondir was given.
1433 +if test "${with_pythondir+set}" = set; then :
1434 +  withval=$with_pythondir; pythondir="${withval}"
1435 +else
1436 +  pythondir=no
1437 +fi
1438 +
1439 +
1440 +# If the user passed in a path, define it.  Otherwise, compute it at
1441 +# runtime based on the possibly-relocatable datadir.
1442 +if test "$pythondir" = "no"; then
1443 +  pythondir='$(GDB_DATADIR_PATH)/python'
1444 +else
1445 +
1446 +cat >>confdefs.h <<_ACEOF
1447 +#define PYTHONDIR "$pythondir"
1448 +_ACEOF
1449 +
1450 +fi
1451 +
1452 +
1453 +
1454  
1455  
1456  subdirs="$subdirs doc testsuite"
1457 @@ -10919,6 +10993,7 @@ $as_echo "#define HAVE_PYTHON 1" >>confdefs.h
1458    CONFIG_DEPS="$CONFIG_DEPS \$(SUBDIR_PYTHON_DEPS)"
1459    CONFIG_SRCS="$CONFIG_SRCS \$(SUBDIR_PYTHON_SRCS)"
1460    CONFIG_INSTALL="$CONFIG_INSTALL install-python"
1461 +  CONFIG_UNINSTALL="$CONFIG_UNINSTALL uninstall-python"
1462    ENABLE_CFLAGS="$ENABLE_CFLAGS \$(SUBDIR_PYTHON_CFLAGS)"
1463  
1464    # Flags needed to compile Python code (taken from python-config --cflags).
1465 diff --git a/gdb/configure.ac b/gdb/configure.ac
1466 index b69c3b6..4e89558 100644
1467 --- a/gdb/configure.ac
1468 +++ b/gdb/configure.ac
1469 @@ -108,6 +108,51 @@ AS_HELP_STRING([--with-relocated-sources=PATH], [automatically relocate this pat
1470                [Relocated directory for source files. ])
1471  ])
1472  
1473 +# GDB's datadir relocation
1474 +
1475 +gdbdatadir=${datadir}/gdb
1476 +
1477 +AC_ARG_WITH([gdb-datadir],
1478 +  [AS_HELP_STRING([--with-gdb-datadir],
1479 +                  [look for global separate data files in this path [DATADIR/gdb]])], [gdbdatadir="${withval}"])
1480 +
1481 +AC_DEFINE_DIR(GDB_DATADIR, gdbdatadir,
1482 +              [Global directory for GDB data files. ])
1483 +
1484 +if test "x$exec_prefix" = xNONE || test "x$exec_prefix" = 'x${prefix}'; then
1485 +  if test "x$prefix" = xNONE; then
1486 +    test_prefix=/usr/local
1487 +  else
1488 +    test_prefix=$prefix
1489 +  fi
1490 +else
1491 +  test_prefix=$exec_prefix
1492 +fi
1493 +
1494 +case ${gdbdatadir} in
1495 +  "${test_prefix}"|"${test_prefix}/"*|\
1496 +  '${exec_prefix}'|'${exec_prefix}/'*)
1497 +    AC_DEFINE(GDB_DATADIR_RELOCATABLE, 1, [Define if GDB datadir should be relocated when GDB is moved.])
1498 +  ;;
1499 +esac
1500 +GDB_DATADIR_PATH=${gdbdatadir}
1501 +AC_SUBST(GDB_DATADIR_PATH)
1502 +
1503 +AC_ARG_WITH([pythondir],
1504 +  [AS_HELP_STRING([--with-pythondir],
1505 +                  [install Python data files in this path [DATADIR/gdb/python]])], [pythondir="${withval}"], [pythondir=no])
1506 +
1507 +# If the user passed in a path, define it.  Otherwise, compute it at
1508 +# runtime based on the possibly-relocatable datadir.
1509 +if test "$pythondir" = "no"; then
1510 +  pythondir='$(GDB_DATADIR_PATH)/python'
1511 +else
1512 +  AC_DEFINE_UNQUOTED(PYTHONDIR, "$pythondir",
1513 +      [Define to install path for Python sources])
1514 +fi
1515 +AC_SUBST(pythondir)
1516 +
1517 +
1518  AC_CONFIG_SUBDIRS(doc testsuite)
1519  
1520  # Check whether to support alternative target configurations
1521 @@ -833,6 +878,7 @@ if test "${have_libpython}" != no; then
1522    CONFIG_DEPS="$CONFIG_DEPS \$(SUBDIR_PYTHON_DEPS)"
1523    CONFIG_SRCS="$CONFIG_SRCS \$(SUBDIR_PYTHON_SRCS)"
1524    CONFIG_INSTALL="$CONFIG_INSTALL install-python"
1525 +  CONFIG_UNINSTALL="$CONFIG_UNINSTALL uninstall-python"
1526    ENABLE_CFLAGS="$ENABLE_CFLAGS \$(SUBDIR_PYTHON_CFLAGS)"
1527  
1528    # Flags needed to compile Python code (taken from python-config --cflags).
1529 diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
1530 index 65d4899..96767b0 100644
1531 --- a/gdb/doc/gdb.texinfo
1532 +++ b/gdb/doc/gdb.texinfo
1533 @@ -1162,6 +1162,16 @@ for remote debugging.
1534  Run using @var{device} for your program's standard input and output.
1535  @c FIXME: kingdon thinks there is more to -tty.  Investigate.
1536  
1537 +@item -P
1538 +@cindex @code{-P}
1539 +@itemx --python
1540 +@cindex @code{--python}
1541 +Change interpretation of command line so that the argument immediately
1542 +following this switch is taken to be the name of a Python script file.
1543 +This option stops option processing; subsequent options are passed to
1544 +Python as @code{sys.argv}.  This option is only available if Python
1545 +scripting support was enabled when @value{GDBN} was configured.
1546 +
1547  @c resolve the situation of these eventually
1548  @item -tui
1549  @cindex @code{--tui}
1550 @@ -14308,6 +14318,7 @@ program.  To debug a core dump of a previous run, you must also tell
1551  @menu
1552  * Files::                       Commands to specify files
1553  * Separate Debug Files::        Debugging information in separate files
1554 +* Index Files::                 Index files speed up GDB
1555  * Symbol Errors::               Errors reading symbol files
1556  * Data Files::                  GDB data files
1557  @end menu
1558 @@ -15197,6 +15208,46 @@ gnu_debuglink_crc32 (unsigned long crc,
1559  This computation does not apply to the ``build ID'' method.
1560  
1561  
1562 +@node Index Files
1563 +@section Index Files Speed Up @value{GDBN}
1564 +@cindex index files
1565 +@cindex @samp{.gdb_index} section
1566 +
1567 +When @value{GDBN} finds a symbol file, it scans the symbols in the
1568 +file in order to construct an internal symbol table.  This lets most
1569 +@value{GDBN} operations work quickly---at the cost of a delay early
1570 +on.  For large programs, this delay can be quite lengthy, so
1571 +@value{GDBN} provides a way to build an index, which speeds up
1572 +startup.
1573 +
1574 +The index is stored as a section in the symbol file.  @value{GDBN} can
1575 +write the index to a file, then you can put it into the symbol file
1576 +using @command{objcopy}.
1577 +
1578 +To create an index file, use the @code{save gdb-index} command:
1579 +
1580 +@table @code
1581 +@item save gdb-index @var{directory}
1582 +@kindex save gdb-index
1583 +Create an index file for each symbol file currently known by
1584 +@value{GDBN}.  Each file is named after its corresponding symbol file,
1585 +with @samp{.gdb-index} appended, and is written into the given
1586 +@var{directory}.
1587 +@end table
1588 +
1589 +Once you have created an index file you can merge it into your symbol
1590 +file, here named @file{symfile}, using @command{objcopy}:
1591 +
1592 +@smallexample
1593 +$ objcopy --add-section .gdb_index=symfile.gdb-index \
1594 +    --set-section-flags .gdb_index=readonly symfile symfile
1595 +@end smallexample
1596 +
1597 +There are currently some limitation on indices.  They only work when
1598 +for DWARF debugging information, not stabs.  And, they do not
1599 +currently work for programs using Ada.
1600 +
1601 +
1602  @node Symbol Errors
1603  @section Errors Reading Symbol Files
1604  
1605 @@ -20349,8 +20400,6 @@ containing @code{end}.  For example:
1606  
1607  @smallexample
1608  (@value{GDBP}) python
1609 -Type python script
1610 -End with a line saying just "end".
1611  >print 23
1612  >end
1613  23
1614 @@ -20363,6 +20412,14 @@ in a Python script.  This can be controlled using @code{maint set
1615  python print-stack}: if @code{on}, the default, then Python stack
1616  printing is enabled; if @code{off}, then Python stack printing is
1617  disabled.
1618 +
1619 +@kindex maint set python auto-load
1620 +@item maint set python auto-load
1621 +By default, @value{GDBN} will attempt to automatically load Python
1622 +code when an object file is opened.  This can be controlled using
1623 +@code{maint set python auto-load}: if @code{on}, the default, then
1624 +Python auto-loading is enabled; if @code{off}, then Python
1625 +auto-loading is disabled.
1626  @end table
1627  
1628  It is also possible to execute a Python script from the @value{GDBN}
1629 @@ -20384,6 +20441,14 @@ and thus is always available.
1630  @cindex python api
1631  @cindex programming in python
1632  
1633 +You can get quick online help for @value{GDBN}'s Python API by issuing
1634 +the command @w{@kbd{python help (gdb)}}.
1635 +
1636 +Functions and methods which have two or more optional arguments allow
1637 +them to be specified using keyword syntax.  This allows passing some
1638 +optional arguments while skipping others.  Example:
1639 +@w{@code{gdb.some_function ('foo', bar = 1, baz = 2)}}.
1640 +
1641  @cindex python stdout
1642  @cindex python pagination
1643  At startup, @value{GDBN} overrides Python's @code{sys.stdout} and
1644 @@ -20395,7 +20460,7 @@ situation, a Python @code{KeyboardInterrupt} exception is thrown.
1645  @menu
1646  * Basic Python::                Basic Python Functions.
1647  * Exception Handling::
1648 -* Values From Inferior::
1649 +* Values From Inferior::       Python representation of values.
1650  * Types In Python::             Python representation of types.
1651  * Pretty Printing API::         Pretty-printing values.
1652  * Selecting Pretty-Printers::   How GDB chooses a pretty-printer.
1653 @@ -20456,6 +20521,12 @@ Return a sequence holding all of @value{GDBN}'s breakpoints.
1654  @xref{Breakpoints In Python}, for more information.
1655  @end defun
1656  
1657 +@findex gdb.breakpoints
1658 +@defun breakpoints
1659 +Return a sequence holding all of @value{GDBN}'s breakpoints.
1660 +@xref{Breakpoints In Python}, for more information.
1661 +@end defun
1662 +
1663  @findex gdb.parameter
1664  @defun parameter parameter
1665  Return the value of a @value{GDBN} parameter.  @var{parameter} is a
1666 @@ -20472,6 +20543,7 @@ a Python value of the appropriate type, and returned.
1667  @defun history number
1668  Return a value from @value{GDBN}'s value history (@pxref{Value
1669  History}).  @var{number} indicates which history element to return.
1670 +
1671  If @var{number} is negative, then @value{GDBN} will take its absolute value
1672  and count backward from the last element (i.e., the most recent element) to
1673  find the value to return.  If @var{number} is zero, then @value{GDBN} will
1674 @@ -20496,6 +20568,21 @@ compute values, for example, it is the only way to get the value of a
1675  convenience variable (@pxref{Convenience Vars}) as a @code{gdb.Value}.
1676  @end defun
1677  
1678 +@findex gdb.post_event
1679 +@defun post_event event
1680 +Put @var{event}, a callable object taking no arguments, into
1681 +@value{GDBN}'s internal event queue.  This callable will be invoked at
1682 +some later point, during @value{GDBN}'s event processing.  Events
1683 +posted using @code{post_event} will be run in the order in which they
1684 +were posted; however, there is no way to know when they will be
1685 +processed relative to other events inside @value{GDBN}.
1686 +
1687 +@value{GDBN} is not thread-safe.  If your Python program uses multiple
1688 +threads, you must be careful to only call @value{GDBN}-specific
1689 +functions in the main @value{GDBN} thread.  @code{post_event} ensures
1690 +this.
1691 +@end defun
1692 +
1693  @findex gdb.write
1694  @defun write string
1695  Print a string to @value{GDBN}'s paginated standard output stream.
1696 diff --git a/gdb/doc/gdbint.texinfo b/gdb/doc/gdbint.texinfo
1697 index 54187dd..320b501 100644
1698 --- a/gdb/doc/gdbint.texinfo
1699 +++ b/gdb/doc/gdbint.texinfo
1700 @@ -2102,6 +2102,18 @@ time, and so we attempt to handle symbols incrementally.  For instance,
1701  we create @dfn{partial symbol tables} consisting of only selected
1702  symbols, and only expand them to full symbol tables when necessary.
1703  
1704 +@menu
1705 +* Symbol Reading::
1706 +* Partial Symbol Tables::
1707 +* Types::
1708 +* Object File Formats::
1709 +* Debugging File Formats::
1710 +* Adding a New Symbol Reader to GDB::
1711 +* Memory Management for Symbol Files::
1712 +* Memory Management for Types::
1713 +@end menu
1714 +
1715 +@node Symbol Reading
1716  @section Symbol Reading
1717  
1718  @cindex symbol reading
1719 @@ -2194,6 +2206,7 @@ symtab.  Upon return, @code{pst->readin} should have been set to 1, and
1720  zero if there were no symbols in that part of the symbol file.
1721  @end table
1722  
1723 +@node Partial Symbol Tables
1724  @section Partial Symbol Tables
1725  
1726  @value{GDBN} has three types of symbol tables:
1727 @@ -2295,6 +2308,7 @@ and partial symbol tables behind a set of function pointers known as
1728  the @dfn{quick symbol functions}.  These are documented in
1729  @file{symfile.h}.
1730  
1731 +@node Types
1732  @section Types
1733  
1734  @unnumberedsubsec Fundamental Types (e.g., @code{FT_VOID}, @code{FT_BOOLEAN}).
1735 @@ -2317,6 +2331,7 @@ types map to one @code{TYPE_CODE_*} type, and are distinguished by
1736  other members of the type struct, such as whether the type is signed
1737  or unsigned, and how many bits it uses.
1738  
1739 +@anchor{Builtin Types}
1740  @unnumberedsubsec Builtin Types (e.g., @code{builtin_type_void}, @code{builtin_type_char}).
1741  
1742  These are instances of type structs that roughly correspond to
1743 @@ -2331,6 +2346,7 @@ only one instance exists, while @file{c-lang.c} builds as many
1744  @code{TYPE_CODE_INT} types as needed, with each one associated with
1745  some particular objfile.
1746  
1747 +@node Object File Formats
1748  @section Object File Formats
1749  @cindex object file formats
1750  
1751 @@ -2416,6 +2432,7 @@ SOM, which is a cross-language ABI).
1752  
1753  The SOM reader is in @file{somread.c}.
1754  
1755 +@node Debugging File Formats
1756  @section Debugging File Formats
1757  
1758  This section describes characteristics of debugging information that
1759 @@ -2487,6 +2504,7 @@ DWARF 3 is an improved version of DWARF 2.
1760  @cindex SOM debugging info
1761  Like COFF, the SOM definition includes debugging information.
1762  
1763 +@node Adding a New Symbol Reader to GDB
1764  @section Adding a New Symbol Reader to @value{GDBN}
1765  
1766  @cindex adding debugging info reader
1767 @@ -2509,6 +2527,7 @@ will only ever be implemented by one object file format may be called
1768  directly.  This interface should be described in a file
1769  @file{bfd/lib@var{xyz}.h}, which is included by @value{GDBN}.
1770  
1771 +@node Memory Management for Symbol Files
1772  @section Memory Management for Symbol Files
1773  
1774  Most memory associated with a loaded symbol file is stored on
1775 @@ -2520,10 +2539,45 @@ released when the objfile is unloaded or reloaded.  Therefore one
1776  objfile must not reference symbol or type data from another objfile;
1777  they could be unloaded at different times.
1778  
1779 -User convenience variables, et cetera, have associated types.  Normally
1780 -these types live in the associated objfile.  However, when the objfile
1781 -is unloaded, those types are deep copied to global memory, so that
1782 -the values of the user variables and history items are not lost.
1783 +@node Memory Management for Types
1784 +@section Memory Management for Types
1785 +@cindex memory management for types
1786 +
1787 +@findex TYPE_OBJFILE
1788 +@code{TYPE_OBJFILE} macro indicates the current memory owner of the type.
1789 +Non-@code{NULL} value indicates it is owned by an objfile (specifically by its
1790 +obstack) and in such case the type remains valid till the objfile is unloaded
1791 +or reloaded.  For such types with an associated objfile no reference counting
1792 +is being made.
1793 +
1794 +User convenience variables, et cetera, have associated types.  Normally these
1795 +types live in the associated objfile.  However, when the objfile is unloaded,
1796 +those types are deep copied to global memory, so that the values of the user
1797 +variables and history items are not lost.  During the copy they will get their
1798 +@code{TYPE_OBJFILE} set to @code{NULL} and become so-called @dfn{reclaimable}
1799 +types.
1800 +
1801 +Types with null @code{TYPE_OBJFILE} can be either permanent types
1802 +(@pxref{Builtin Types}) or reclaimable types which will be deallocated at the
1803 +first idle @value{GDBN} moment if the last object referencing them is removed.
1804 +Permanent types are allocated by the function @code{alloc_type} (and its
1805 +derivations like @code{init_type}) specifying objfile as @code{NULL}.  The
1806 +reclaimable types are created the same way but moreover they need to have
1807 +@code{type_init_group} called to start their tracking as being possibly
1808 +deallocatable.
1809 +
1810 +@findex free_all_types
1811 +When @value{GDBN} gets idle it always calls the @code{free_all_types} function
1812 +which deallocates any unused types.  All types currently not owned by an
1813 +objfile must be marked as used on each @code{free_all_types} call as they would
1814 +get deallocated as unused otherwise.
1815 +
1816 +@code{free_all_types} automatically checks for any cross-type references such
1817 +as through @code{TYPE_TARGET_TYPE}, @code{TYPE_POINTER_TYPE} etc.@: and
1818 +prevents early deallocation for any such existing references.  Reclaimable
1819 +types may reference any other reclaimable types or even permanent types.  But
1820 +permanent types must not reference reclaimable types (nor an objfile associated
1821 +type).
1822  
1823  
1824  @node Language Support
1825 diff --git a/gdb/doc/observer.texi b/gdb/doc/observer.texi
1826 index e19b8ed..343e160 100644
1827 --- a/gdb/doc/observer.texi
1828 +++ b/gdb/doc/observer.texi
1829 @@ -223,6 +223,11 @@ Bytes from @var{data} to @var{data} + @var{len} have been written
1830  to the current inferior at @var{addr}.
1831  @end deftypefun
1832  
1833 +@deftypefun void mark_used (void)
1834 +Mark any possibly reclaimable objects as used during a mark-and-sweep garbage
1835 +collector pass.  Currently only @code{type_mark_used} marker is supported.
1836 +@end deftypefun
1837 +
1838  @deftypefun void test_notification (int @var{somearg})
1839  This observer is used for internal testing.  Do not use.  
1840  See testsuite/gdb.gdb/observer.exp.
1841 diff --git a/gdb/dwarf2expr.c b/gdb/dwarf2expr.c
1842 index b9ae108..2555908 100644
1843 --- a/gdb/dwarf2expr.c
1844 +++ b/gdb/dwarf2expr.c
1845 @@ -875,6 +875,13 @@ execute_stack_op (struct dwarf_expr_context *ctx,
1846           ctx->dwarf_call (ctx, result);
1847           goto no_push;
1848  
1849 +       case DW_OP_push_object_address:
1850 +         if (ctx->get_object_address == NULL)
1851 +           error (_("DWARF-2 expression error: DW_OP_push_object_address must "
1852 +                  "have a value to push."));
1853 +         result = (ctx->get_object_address) (ctx->baton);
1854 +         break;
1855 +
1856         default:
1857           error (_("Unhandled dwarf expression opcode 0x%x"), op);
1858         }
1859 diff --git a/gdb/dwarf2expr.h b/gdb/dwarf2expr.h
1860 index 61b8f00..d94c03c 100644
1861 --- a/gdb/dwarf2expr.h
1862 +++ b/gdb/dwarf2expr.h
1863 @@ -108,9 +108,15 @@ struct dwarf_expr_context
1864  #if 0
1865    /* Not yet implemented.  */
1866  
1867 +  /* Return the location expression for the dwarf expression
1868 +     subroutine in the die at OFFSET in the current compilation unit.
1869 +     The result must be live until the current expression evaluation
1870 +     is complete.  */
1871 +  unsigned char *(*get_subr) (void *baton, off_t offset, size_t *length);
1872 +#endif
1873 +
1874    /* Return the `object address' for DW_OP_push_object_address.  */
1875    CORE_ADDR (*get_object_address) (void *baton);
1876 -#endif
1877  
1878    /* The current depth of dwarf expression recursion, via DW_OP_call*,
1879       DW_OP_fbreg, DW_OP_push_object_address, etc., and the maximum
1880 diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
1881 index f59bc40..7ff0ef9 100644
1882 --- a/gdb/dwarf2loc.c
1883 +++ b/gdb/dwarf2loc.c
1884 @@ -48,6 +48,12 @@ static void
1885  dwarf_expr_frame_base_1 (struct symbol *framefunc, CORE_ADDR pc,
1886                          const gdb_byte **start, size_t *length);
1887  
1888 +static struct value *dwarf2_evaluate_loc_desc (struct type *type,
1889 +                                              struct frame_info *frame,
1890 +                                              const gdb_byte *data,
1891 +                                              unsigned short size,
1892 +                                            struct dwarf2_per_cu_data *per_cu);
1893 +
1894  /* A helper function for dealing with location lists.  Given a
1895     symbol baton (BATON) and a pc value (PC), find the appropriate
1896     location expression, set *LOCEXPR_LENGTH, and return a pointer
1897 @@ -127,6 +133,9 @@ struct dwarf_expr_baton
1898  {
1899    struct frame_info *frame;
1900    struct dwarf2_per_cu_data *per_cu;
1901 +  /* From DW_TAG_variable's DW_AT_location (not DW_TAG_type's
1902 +     DW_AT_data_location) for DW_OP_push_object_address.  */
1903 +  CORE_ADDR object_address;
1904  };
1905  
1906  /* Helper functions for dwarf2_evaluate_loc_desc.  */
1907 @@ -195,23 +204,33 @@ dwarf_expr_frame_base_1 (struct symbol *framefunc, CORE_ADDR pc,
1908        symbaton = SYMBOL_LOCATION_BATON (framefunc);
1909        *start = find_location_expression (symbaton, length, pc);
1910      }
1911 -  else
1912 +  else if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_locexpr_funcs)
1913      {
1914        struct dwarf2_locexpr_baton *symbaton;
1915  
1916        symbaton = SYMBOL_LOCATION_BATON (framefunc);
1917 -      if (symbaton != NULL)
1918 -       {
1919 -         *length = symbaton->size;
1920 -         *start = symbaton->data;
1921 -       }
1922 -      else
1923 -       *start = NULL;
1924 +      gdb_assert (symbaton != NULL);
1925 +      *start = symbaton->data;
1926 +      *length = symbaton->size;
1927      }
1928 +  else if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_missing_funcs)
1929 +    {
1930 +      struct dwarf2_locexpr_baton *symbaton;
1931 +
1932 +      symbaton = SYMBOL_LOCATION_BATON (framefunc);
1933 +      gdb_assert (symbaton == NULL);
1934 +      *start = NULL;
1935 +      *length = 0;     /* unused */
1936 +    }
1937 +  else
1938 +    internal_error (__FILE__, __LINE__,
1939 +                   _("Unsupported SYMBOL_COMPUTED_OPS %p for \"%s\""),
1940 +                   SYMBOL_COMPUTED_OPS (framefunc),
1941 +                   SYMBOL_PRINT_NAME (framefunc));
1942  
1943    if (*start == NULL)
1944      error (_("Could not find the frame base for \"%s\"."),
1945 -          SYMBOL_NATURAL_NAME (framefunc));
1946 +          SYMBOL_PRINT_NAME (framefunc));
1947  }
1948  
1949  /* Helper function for dwarf2_evaluate_loc_desc.  Computes the CFA for
1950 @@ -263,6 +282,158 @@ dwarf_expr_dwarf_call (struct dwarf_expr_context *ctx, size_t die_offset)
1951    return per_cu_dwarf_call (ctx, die_offset, debaton->per_cu);
1952  }
1953  
1954 +static CORE_ADDR
1955 +dwarf_expr_object_address (void *baton)
1956 +{
1957 +  struct dwarf_expr_baton *debaton = baton;
1958 +
1959 +  /* The message is suppressed in DWARF_BLOCK_EXEC.  */
1960 +  if (debaton->object_address == 0)
1961 +    error (_("Cannot resolve DW_OP_push_object_address for a missing object"));
1962 +
1963 +  return debaton->object_address;
1964 +}
1965 +
1966 +/* Address of the variable we are currently referring to.  It is set from
1967 +   DW_TAG_variable's DW_AT_location (not DW_TAG_type's DW_AT_data_location) for
1968 +   DW_OP_push_object_address.  */
1969 +
1970 +static CORE_ADDR object_address;
1971 +
1972 +/* Callers use object_address_set while their callers use the result set so we
1973 +   cannot run the cleanup at the local block of our direct caller.  Still we
1974 +   should reset OBJECT_ADDRESS at least for the next GDB command.  */
1975 +
1976 +static void
1977 +object_address_cleanup (void *prev_save_voidp)
1978 +{
1979 +  CORE_ADDR *prev_save = prev_save_voidp;
1980 +
1981 +  object_address = *prev_save;
1982 +  xfree (prev_save);
1983 +}
1984 +
1985 +/* Set the base address - DW_AT_location - of a variable.  It is being later
1986 +   used to derive other object addresses by DW_OP_push_object_address.
1987 +
1988 +   It would be useful to sanity check ADDRESS - such as for some objects with
1989 +   unset value_raw_address - but some valid addresses may be zero (such as first
1990 +   objects in relocatable .o files).  */
1991 +
1992 +void
1993 +object_address_set (CORE_ADDR address)
1994 +{
1995 +  CORE_ADDR *prev_save;
1996 +
1997 +  prev_save = xmalloc (sizeof *prev_save);
1998 +  *prev_save = object_address;
1999 +  make_cleanup (object_address_cleanup, prev_save);
2000 +
2001 +  object_address = address;
2002 +}
2003 +
2004 +/* Evaluate DWARF expression at DATA ... DATA + SIZE with its result readable
2005 +   by dwarf_expr_fetch (RETVAL, 0).  FRAME parameter can be NULL to call
2006 +   get_selected_frame to find it.  Returned dwarf_expr_context freeing is
2007 +   pushed on the cleanup chain.  */
2008 +
2009 +static struct dwarf_expr_context *
2010 +dwarf_expr_prep_ctx (struct frame_info *frame, const gdb_byte *data,
2011 +                    size_t size, struct dwarf2_per_cu_data *per_cu)
2012 +{
2013 +  struct dwarf_expr_context *ctx;
2014 +  struct dwarf_expr_baton baton;
2015 +  struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
2016 +
2017 +  baton.frame = frame;
2018 +  baton.per_cu = per_cu;
2019 +  baton.object_address = object_address;
2020 +
2021 +  ctx = new_dwarf_expr_context ();
2022 +  make_cleanup_free_dwarf_expr_context (ctx);
2023 +
2024 +  ctx->gdbarch = get_objfile_arch (objfile);
2025 +  ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
2026 +  ctx->offset = dwarf2_per_cu_text_offset (per_cu);
2027 +  ctx->baton = &baton;
2028 +  ctx->read_reg = dwarf_expr_read_reg;
2029 +  ctx->read_mem = dwarf_expr_read_mem;
2030 +  ctx->get_frame_base = dwarf_expr_frame_base;
2031 +  ctx->get_frame_cfa = dwarf_expr_frame_cfa;
2032 +  ctx->get_tls_address = dwarf_expr_tls_address;
2033 +  ctx->dwarf_call = dwarf_expr_dwarf_call;
2034 +  ctx->get_object_address = dwarf_expr_object_address;
2035 +
2036 +  dwarf_expr_eval (ctx, data, size);
2037 +
2038 +  /* It was used only during dwarf_expr_eval.  */
2039 +  ctx->baton = NULL;
2040 +
2041 +  return ctx;
2042 +}
2043 +
2044 +/* Evaluate DWARF expression at DLBATON expecting it produces exactly one
2045 +   CORE_ADDR result on the DWARF stack stack.  */
2046 +
2047 +CORE_ADDR
2048 +dwarf_locexpr_baton_eval (struct dwarf2_locexpr_baton *dlbaton)
2049 +{
2050 +  struct dwarf_expr_context *ctx;
2051 +  CORE_ADDR retval;
2052 +  struct cleanup *back_to = make_cleanup (null_cleanup, 0);
2053 +
2054 +  ctx = dwarf_expr_prep_ctx (get_selected_frame (NULL), dlbaton->data,
2055 +                            dlbaton->size, dlbaton->per_cu);
2056 +  if (ctx->num_pieces > 0)
2057 +    error (_("DW_OP_*piece is unsupported for DW_FORM_block"));
2058 +
2059 +  retval = dwarf_expr_fetch (ctx, 0);
2060 +
2061 +  if (ctx->location == DWARF_VALUE_REGISTER)
2062 +    {
2063 +      /* Inlined dwarf_expr_read_reg as we no longer have the baton. */
2064 +
2065 +      int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (ctx->gdbarch, retval);
2066 +      struct type *type = builtin_type (ctx->gdbarch)->builtin_data_ptr;
2067 +      struct frame_info *frame = get_selected_frame (NULL);
2068 +
2069 +      retval = address_from_register (type, gdb_regnum, frame);
2070 +    }
2071 +
2072 +  do_cleanups (back_to);
2073 +
2074 +  return retval;
2075 +}
2076 +
2077 +/* Evaluate DWARF location list at DLLBATON expecting it produces exactly one
2078 +   CORE_ADDR result stored to *ADDRP on the DWARF stack stack.  If the result
2079 +   could not be found return zero and keep *ADDRP unchanged.  */
2080 +
2081 +int
2082 +dwarf_loclist_baton_eval (struct dwarf2_loclist_baton *dllbaton,
2083 +                         struct type *type, CORE_ADDR *addrp)
2084 +{
2085 +  struct frame_info *frame = get_selected_frame (NULL);
2086 +  const gdb_byte *data;
2087 +  size_t size;
2088 +  struct value *val;
2089 +
2090 +  if (!dllbaton)
2091 +    return 0;
2092 +
2093 +  data = find_location_expression (dllbaton, &size,
2094 +                                  get_frame_address_in_block (frame));
2095 +  if (data == NULL)
2096 +    return 0;
2097 +
2098 +  val = dwarf2_evaluate_loc_desc (type, frame, data, size, dllbaton->per_cu);
2099 +  if (value_optimized_out (val))
2100 +    return 0;
2101 +
2102 +  *addrp = value_as_address (val);
2103 +  return 1;
2104 +}
2105 +
2106  struct piece_closure
2107  {
2108    /* Reference count.  */
2109 @@ -887,10 +1058,8 @@ dwarf2_evaluate_loc_desc (struct type *type, struct frame_info *frame,
2110                           struct dwarf2_per_cu_data *per_cu)
2111  {
2112    struct value *retval;
2113 -  struct dwarf_expr_baton baton;
2114    struct dwarf_expr_context *ctx;
2115 -  struct cleanup *old_chain;
2116 -  struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
2117 +  struct cleanup *old_chain = make_cleanup (null_cleanup, 0);
2118  
2119    if (size == 0)
2120      {
2121 @@ -900,24 +1069,8 @@ dwarf2_evaluate_loc_desc (struct type *type, struct frame_info *frame,
2122        return retval;
2123      }
2124  
2125 -  baton.frame = frame;
2126 -  baton.per_cu = per_cu;
2127 +  ctx = dwarf_expr_prep_ctx (frame, data, size, per_cu);
2128  
2129 -  ctx = new_dwarf_expr_context ();
2130 -  old_chain = make_cleanup_free_dwarf_expr_context (ctx);
2131 -
2132 -  ctx->gdbarch = get_objfile_arch (objfile);
2133 -  ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
2134 -  ctx->offset = dwarf2_per_cu_text_offset (per_cu);
2135 -  ctx->baton = &baton;
2136 -  ctx->read_reg = dwarf_expr_read_reg;
2137 -  ctx->read_mem = dwarf_expr_read_mem;
2138 -  ctx->get_frame_base = dwarf_expr_frame_base;
2139 -  ctx->get_frame_cfa = dwarf_expr_frame_cfa;
2140 -  ctx->get_tls_address = dwarf_expr_tls_address;
2141 -  ctx->dwarf_call = dwarf_expr_dwarf_call;
2142 -
2143 -  dwarf_expr_eval (ctx, data, size);
2144    if (ctx->num_pieces > 0)
2145      {
2146        struct piece_closure *c;
2147 @@ -951,6 +1104,11 @@ dwarf2_evaluate_loc_desc (struct type *type, struct frame_info *frame,
2148             CORE_ADDR address = dwarf_expr_fetch_address (ctx, 0);
2149             int in_stack_memory = dwarf_expr_fetch_in_stack_memory (ctx, 0);
2150  
2151 +           /* object_address_set called here is required in ALLOCATE_VALUE's
2152 +              CHECK_TYPEDEF for the object's possible
2153 +              DW_OP_push_object_address.  */
2154 +           object_address_set (address);
2155 +
2156             retval = allocate_value (type);
2157             VALUE_LVAL (retval) = lval_memory;
2158             set_value_lazy (retval, 1);
2159 @@ -2590,11 +2748,51 @@ loclist_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
2160                          dlbaton->per_cu);
2161  }
2162  
2163 -/* The set of location functions used with the DWARF-2 expression
2164 -   evaluator and location lists.  */
2165 +/* The set of location functions used with the DWARF-2 location lists.  */
2166  const struct symbol_computed_ops dwarf2_loclist_funcs = {
2167    loclist_read_variable,
2168    loclist_read_needs_frame,
2169    loclist_describe_location,
2170    loclist_tracepoint_var_ref
2171  };
2172 +
2173 +static struct value *
2174 +missing_read_variable (struct symbol *symbol, struct frame_info *frame)
2175 +{
2176 +  struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
2177 +
2178 +  gdb_assert (dlbaton == NULL);
2179 +  error (_("Unable to resolve variable \"%s\""), SYMBOL_PRINT_NAME (symbol));
2180 +}
2181 +
2182 +static int
2183 +missing_read_needs_frame (struct symbol *symbol)
2184 +{
2185 +  return 0;
2186 +}
2187 +
2188 +static void
2189 +missing_describe_location (struct symbol *symbol, CORE_ADDR addr,
2190 +                          struct ui_file *stream)
2191 +{
2192 +  fprintf_filtered (stream, _("a variable we are unable to resolve"));
2193 +}
2194 +
2195 +static void
2196 +missing_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
2197 +                           struct agent_expr *ax, struct axs_value *value)
2198 +{
2199 +  struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
2200 +
2201 +  gdb_assert (dlbaton == NULL);
2202 +  error (_("Unable to resolve variable \"%s\""), SYMBOL_PRINT_NAME (symbol));
2203 +}
2204 +
2205 +/* The set of location functions used with the DWARF-2 evaluator when we are
2206 +   unable to resolve the symbols.  */
2207 +const struct symbol_computed_ops dwarf2_missing_funcs = {
2208 +  missing_read_variable,
2209 +  missing_read_needs_frame,
2210 +  missing_describe_location,
2211 +  missing_tracepoint_var_ref
2212 +};
2213 diff --git a/gdb/dwarf2loc.h b/gdb/dwarf2loc.h
2214 index 826bc45..1e7d8dc 100644
2215 --- a/gdb/dwarf2loc.h
2216 +++ b/gdb/dwarf2loc.h
2217 @@ -86,5 +86,14 @@ struct dwarf2_loclist_baton
2218  
2219  extern const struct symbol_computed_ops dwarf2_locexpr_funcs;
2220  extern const struct symbol_computed_ops dwarf2_loclist_funcs;
2221 +extern const struct symbol_computed_ops dwarf2_missing_funcs;
2222 +
2223 +extern void object_address_set (CORE_ADDR address);
2224 +
2225 +extern CORE_ADDR dwarf_locexpr_baton_eval
2226 +  (struct dwarf2_locexpr_baton *dlbaton);
2227 +
2228 +extern int dwarf_loclist_baton_eval (struct dwarf2_loclist_baton *dllbaton,
2229 +                                    struct type *type, CORE_ADDR *addrp);
2230  
2231  #endif /* dwarf2loc.h */
2232 diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
2233 index 1e75235..d54e266 100644
2234 --- a/gdb/dwarf2read.c
2235 +++ b/gdb/dwarf2read.c
2236 @@ -51,6 +51,9 @@
2237  #include "typeprint.h"
2238  #include "jv-lang.h"
2239  #include "psympriv.h"
2240 +#include "exceptions.h"
2241 +#include "gdb_stat.h"
2242 +#include "completer.h"
2243  
2244  #include <fcntl.h>
2245  #include "gdb_string.h"
2246 @@ -129,6 +132,33 @@ struct dwarf2_section_info
2247    int readin;
2248  };
2249  
2250 +/* All offsets in the index are of this type.  It must be
2251 +   architecture-independent.  */
2252 +typedef uint32_t offset_type;
2253 +
2254 +DEF_VEC_I (offset_type);
2255 +
2256 +/* A description of the mapped index.  The file format is described in
2257 +   a comment by the code that writes the index.  */
2258 +struct mapped_index
2259 +{
2260 +  /* The total length of the buffer.  */
2261 +  off_t total_size;
2262 +  /* A pointer to the address table data.  */
2263 +  const gdb_byte *address_table;
2264 +  /* Size of the address table data in bytes.  */
2265 +  offset_type address_table_size;
2266 +  /* The hash table.  */
2267 +  const offset_type *index_table;
2268 +  /* Size in slots, each slot is 2 offset_types.  */
2269 +  offset_type index_table_slots;
2270 +  /* A pointer to the constant pool.  */
2271 +  const char *constant_pool;
2272 +};
2273 +
2274 +typedef struct dwarf2_per_cu_data *dwarf2_per_cu_data_ptr;
2275 +DEF_VEC_P (dwarf2_per_cu_data_ptr);
2276 +
2277  struct dwarf2_per_objfile
2278  {
2279    struct dwarf2_section_info info;
2280 @@ -141,6 +171,7 @@ struct dwarf2_per_objfile
2281    struct dwarf2_section_info types;
2282    struct dwarf2_section_info frame;
2283    struct dwarf2_section_info eh_frame;
2284 +  struct dwarf2_section_info gdb_index;
2285  
2286    /* Back link.  */
2287    struct objfile *objfile;
2288 @@ -163,6 +194,12 @@ struct dwarf2_per_objfile
2289    /* A flag indicating wether this objfile has a section loaded at a
2290       VMA of 0.  */
2291    int has_section_at_zero;
2292 +
2293 +  /* True if we are using the mapped index.  */
2294 +  unsigned char using_index;
2295 +
2296 +  /* The mapped index.  */
2297 +  struct mapped_index *index_table;
2298  };
2299  
2300  static struct dwarf2_per_objfile *dwarf2_per_objfile;
2301 @@ -182,6 +219,7 @@ static struct dwarf2_per_objfile *dwarf2_per_objfile;
2302  #define TYPES_SECTION    "debug_types"
2303  #define FRAME_SECTION    "debug_frame"
2304  #define EH_FRAME_SECTION "eh_frame"
2305 +#define GDB_INDEX_SECTION "gdb_index"
2306  
2307  /* local data types */
2308  
2309 @@ -307,6 +345,32 @@ struct dwarf2_cu
2310    unsigned int has_namespace_info : 1;
2311  };
2312  
2313 +/* When using the index (and thus not using psymtabs), each CU has an
2314 +   object of this type.  This is used to hold information needed by
2315 +   the various "quick" methods.  */
2316 +struct dwarf2_per_cu_quick_data
2317 +{
2318 +  /* The line table.  This can be NULL if there was no line table.  */
2319 +  struct line_header *lines;
2320 +
2321 +  /* The file names from the line table.  */
2322 +  const char **file_names;
2323 +  /* The file names from the line table after being run through
2324 +     gdb_realpath.  */
2325 +  const char **full_names;
2326 +
2327 +  /* The corresponding symbol table.  This is NULL if symbols for this
2328 +     CU have not yet been read.  */
2329 +  struct symtab *symtab;
2330 +
2331 +  /* A temporary mark bit used when iterating over all CUs in
2332 +     expand_symtabs_matching.  */
2333 +  unsigned int mark : 1;
2334 +
2335 +  /* True if we've tried to read the line table.  */
2336 +  unsigned int read_lines : 1;
2337 +};
2338 +
2339  /* Persistent data held for a compilation unit, even when not
2340     processing it.  We put a pointer to this structure in the
2341     read_symtab_private field of the psymtab.  If we encounter
2342 @@ -347,10 +411,21 @@ struct dwarf2_per_cu_data
2343       it.  */
2344    htab_t type_hash;
2345  
2346 -  /* The partial symbol table associated with this compilation unit,
2347 -     or NULL for partial units (which do not have an associated
2348 -     symtab).  */
2349 -  struct partial_symtab *psymtab;
2350 +  /* The corresponding objfile.  */
2351 +  struct objfile *objfile;
2352 +
2353 +  /* When using partial symbol tables, the 'psymtab' field is active.
2354 +     Otherwise the 'quick' field is active.  */
2355 +  union
2356 +  {
2357 +    /* The partial symbol table associated with this compilation unit,
2358 +       or NULL for partial units (which do not have an associated
2359 +       symtab).  */
2360 +    struct partial_symtab *psymtab;
2361 +
2362 +    /* Data needed by the "quick" functions.  */
2363 +    struct dwarf2_per_cu_quick_data *quick;
2364 +  } v;
2365  };
2366  
2367  /* Entry in the signatured_types hash table.  */
2368 @@ -1083,6 +1158,9 @@ static int attr_form_is_section_offset (struct attribute *);
2369  
2370  static int attr_form_is_constant (struct attribute *);
2371  
2372 +static struct dwarf2_loclist_baton *dwarf2_attr_to_loclist_baton
2373 +  (struct attribute *attr, struct dwarf2_cu *cu);
2374 +
2375  static void dwarf2_symbol_mark_computed (struct attribute *attr,
2376                                          struct symbol *sym,
2377                                          struct dwarf2_cu *cu);
2378 @@ -1113,6 +1191,9 @@ static void age_cached_comp_units (void);
2379  
2380  static void free_one_cached_comp_unit (void *);
2381  
2382 +static void fetch_die_type_attrs (struct die_info *die, struct type *type,
2383 +                                 struct dwarf2_cu *cu);
2384 +
2385  static struct type *set_die_type (struct die_info *, struct type *,
2386                                   struct dwarf2_cu *);
2387  
2388 @@ -1132,6 +1213,56 @@ static void dwarf2_clear_marks (struct dwarf2_per_cu_data *);
2389  
2390  static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
2391  
2392 +static struct dwarf2_locexpr_baton *dwarf2_attr_to_locexpr_baton
2393 +  (struct attribute *attr, struct dwarf2_cu *cu);
2394 +
2395 +static void dwarf2_release_queue (void *dummy);
2396 +
2397 +static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu,
2398 +                            struct objfile *objfile);
2399 +
2400 +static void process_queue (struct objfile *objfile);
2401 +
2402 +static void find_file_and_directory (struct die_info *die,
2403 +                                    struct dwarf2_cu *cu,
2404 +                                    char **name, char **comp_dir);
2405 +
2406 +static char *file_full_name (int file, struct line_header *lh,
2407 +                            const char *comp_dir);
2408 +
2409 +static gdb_byte *partial_read_comp_unit_head (struct comp_unit_head *header,
2410 +                                             gdb_byte *info_ptr,
2411 +                                             gdb_byte *buffer,
2412 +                                             unsigned int buffer_size,
2413 +                                             bfd *abfd);
2414 +
2415 +static void init_cu_die_reader (struct die_reader_specs *reader,
2416 +                               struct dwarf2_cu *cu);
2417 +
2418 +#if WORDS_BIGENDIAN
2419 +
2420 +/* Convert VALUE between big- and little-endian.  */
2421 +static offset_type
2422 +byte_swap (offset_type value)
2423 +{
2424 +  offset_type result;
2425 +
2426 +  result = (value & 0xff) << 24;
2427 +  result |= (value & 0xff00) << 8;
2428 +  result |= (value & 0xff0000) >> 8;
2429 +  result |= (value & 0xff000000) >> 24;
2430 +  return result;
2431 +}
2432 +
2433 +#define MAYBE_SWAP(V)  byte_swap (V)
2434 +
2435 +#else
2436 +#define MAYBE_SWAP(V) (V)
2437 +#endif /* WORDS_BIGENDIAN */
2438 +
2439 +/* The suffix for an index file.  */
2440 +#define INDEX_SUFFIX ".gdb-index"
2441 +
2442  /* Try to locate the sections we need for DWARF 2 debugging
2443     information and return true if we have enough to do something.  */
2444  
2445 @@ -1230,6 +1361,11 @@ dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr)
2446        dwarf2_per_objfile->types.asection = sectp;
2447        dwarf2_per_objfile->types.size = bfd_get_section_size (sectp);
2448      }
2449 +  else if (section_is_p (sectp->name, GDB_INDEX_SECTION))
2450 +    {
2451 +      dwarf2_per_objfile->gdb_index.asection = sectp;
2452 +      dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp);
2453 +    }
2454  
2455    if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD)
2456        && bfd_section_vma (abfd, sectp) == 0)
2457 @@ -1353,87 +1489,940 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
2458    if (pagesize == 0)
2459      pagesize = getpagesize ();
2460  
2461 -  /* Only try to mmap sections which are large enough: we don't want to
2462 -     waste space due to fragmentation.  Also, only try mmap for sections
2463 -     without relocations.  */
2464 +  /* Only try to mmap sections which are large enough: we don't want to
2465 +     waste space due to fragmentation.  Also, only try mmap for sections
2466 +     without relocations.  */
2467 +
2468 +  if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0)
2469 +    {
2470 +      off_t pg_offset = sectp->filepos & ~(pagesize - 1);
2471 +      size_t map_length = info->size + sectp->filepos - pg_offset;
2472 +      caddr_t retbuf = bfd_mmap (abfd, 0, map_length, PROT_READ,
2473 +                                MAP_PRIVATE, pg_offset);
2474 +
2475 +      if (retbuf != MAP_FAILED)
2476 +       {
2477 +         info->was_mmapped = 1;
2478 +         info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ;
2479 +#if HAVE_POSIX_MADVISE
2480 +         posix_madvise (retbuf, map_length, POSIX_MADV_WILLNEED);
2481 +#endif
2482 +         return;
2483 +       }
2484 +    }
2485 +#endif
2486 +
2487 +  /* If we get here, we are a normal, not-compressed section.  */
2488 +  info->buffer = buf
2489 +    = obstack_alloc (&objfile->objfile_obstack, info->size);
2490 +
2491 +  /* When debugging .o files, we may need to apply relocations; see
2492 +     http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2493 +     We never compress sections in .o files, so we only need to
2494 +     try this when the section is not compressed.  */
2495 +  retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
2496 +  if (retbuf != NULL)
2497 +    {
2498 +      info->buffer = retbuf;
2499 +      return;
2500 +    }
2501 +
2502 +  if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
2503 +      || bfd_bread (buf, info->size, abfd) != info->size)
2504 +    error (_("Dwarf Error: Can't read DWARF data from '%s'"),
2505 +          bfd_get_filename (abfd));
2506 +}
2507 +
2508 +/* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2509 +   SECTION_NAME. */
2510 +
2511 +void
2512 +dwarf2_get_section_info (struct objfile *objfile, const char *section_name,
2513 +                         asection **sectp, gdb_byte **bufp,
2514 +                         bfd_size_type *sizep)
2515 +{
2516 +  struct dwarf2_per_objfile *data
2517 +    = objfile_data (objfile, dwarf2_objfile_data_key);
2518 +  struct dwarf2_section_info *info;
2519 +
2520 +  /* We may see an objfile without any DWARF, in which case we just
2521 +     return nothing.  */
2522 +  if (data == NULL)
2523 +    {
2524 +      *sectp = NULL;
2525 +      *bufp = NULL;
2526 +      *sizep = 0;
2527 +      return;
2528 +    }
2529 +  if (section_is_p (section_name, EH_FRAME_SECTION))
2530 +    info = &data->eh_frame;
2531 +  else if (section_is_p (section_name, FRAME_SECTION))
2532 +    info = &data->frame;
2533 +  else
2534 +    gdb_assert (0);
2535 +
2536 +  if (info->asection != NULL && info->size != 0 && info->buffer == NULL)
2537 +    /* We haven't read this section in yet.  Do it now.  */
2538 +    dwarf2_read_section (objfile, info);
2539 +
2540 +  *sectp = info->asection;
2541 +  *bufp = info->buffer;
2542 +  *sizep = info->size;
2543 +}
2544 +
2545 +\f
2546 +
2547 +/* Read in the symbols for PER_CU.  OBJFILE is the objfile from which
2548 +   this CU came.  */
2549 +static void
2550 +dw2_do_instantiate_symtab (struct objfile *objfile,
2551 +                          struct dwarf2_per_cu_data *per_cu)
2552 +{
2553 +  struct cleanup *back_to;
2554 +
2555 +  back_to = make_cleanup (dwarf2_release_queue, NULL);
2556 +
2557 +  queue_comp_unit (per_cu, objfile);
2558 +
2559 +  if (per_cu->from_debug_types)
2560 +    read_signatured_type_at_offset (objfile, per_cu->offset);
2561 +  else
2562 +    load_full_comp_unit (per_cu, objfile);
2563 +
2564 +  process_queue (objfile);
2565 +
2566 +  /* Age the cache, releasing compilation units that have not
2567 +     been used recently.  */
2568 +  age_cached_comp_units ();
2569 +
2570 +  do_cleanups (back_to);
2571 +}
2572 +
2573 +/* Ensure that the symbols for PER_CU have been read in.  OBJFILE is
2574 +   the objfile from which this CU came.  Returns the resulting symbol
2575 +   table.  */
2576 +static struct symtab *
2577 +dw2_instantiate_symtab (struct objfile *objfile,
2578 +                       struct dwarf2_per_cu_data *per_cu)
2579 +{
2580 +  if (!per_cu->v.quick->symtab)
2581 +    {
2582 +      struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL);
2583 +      increment_reading_symtab ();
2584 +      dw2_do_instantiate_symtab (objfile, per_cu);
2585 +      do_cleanups (back_to);
2586 +    }
2587 +  return per_cu->v.quick->symtab;
2588 +}
2589 +
2590 +/* A helper function that knows how to read a 64-bit value in a way
2591 +   that doesn't make gdb die.  Returns 1 if the conversion went ok, 0
2592 +   otherwise.  */
2593 +static int
2594 +extract_cu_value (const char *bytes, ULONGEST *result)
2595 +{
2596 +  if (sizeof (ULONGEST) < 8)
2597 +    {
2598 +      int i;
2599 +
2600 +      /* Ignore the upper 4 bytes if they are all zero.  */
2601 +      for (i = 0; i < 4; ++i)
2602 +       if (bytes[i + 4] != 0)
2603 +         return 0;
2604 +
2605 +      *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE);
2606 +    }
2607 +  else
2608 +    *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE);
2609 +  return 1;
2610 +}
2611 +
2612 +/* Read the CU list from the mapped index, and use it to create all
2613 +   the CU objects for this objfile.  Return 0 if something went wrong,
2614 +   1 if everything went ok.  */
2615 +static int
2616 +create_cus_from_index (struct objfile *objfile, struct mapped_index *index,
2617 +                      const gdb_byte *cu_list, offset_type cu_list_elements)
2618 +{
2619 +  offset_type i;
2620 +  const char *entry;
2621 +
2622 +  dwarf2_per_objfile->n_comp_units = cu_list_elements / 2;
2623 +  dwarf2_per_objfile->all_comp_units
2624 +    = obstack_alloc (&objfile->objfile_obstack,
2625 +                    dwarf2_per_objfile->n_comp_units
2626 +                    * sizeof (struct dwarf2_per_cu_data *));
2627 +
2628 +  for (i = 0; i < cu_list_elements; i += 2)
2629 +    {
2630 +      struct dwarf2_per_cu_data *the_cu;
2631 +      ULONGEST offset, length;
2632 +
2633 +      if (!extract_cu_value (cu_list, &offset)
2634 +         || !extract_cu_value (cu_list + 8, &length))
2635 +       return 0;
2636 +      cu_list += 2 * 8;
2637 +
2638 +      the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2639 +                              struct dwarf2_per_cu_data);
2640 +      the_cu->offset = offset;
2641 +      the_cu->length = length;
2642 +      the_cu->objfile = objfile;
2643 +      the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2644 +                                       struct dwarf2_per_cu_quick_data);
2645 +      dwarf2_per_objfile->all_comp_units[i / 2] = the_cu;
2646 +    }
2647 +
2648 +  return 1;
2649 +}
2650 +
2651 +/* Read the address map data from the mapped index, and use it to
2652 +   populate the objfile's psymtabs_addrmap.  */
2653 +static void
2654 +create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index)
2655 +{
2656 +  const gdb_byte *iter, *end;
2657 +  struct obstack temp_obstack;
2658 +  struct addrmap *mutable_map;
2659 +  struct cleanup *cleanup;
2660 +  CORE_ADDR baseaddr;
2661 +
2662 +  obstack_init (&temp_obstack);
2663 +  cleanup = make_cleanup_obstack_free (&temp_obstack);
2664 +  mutable_map = addrmap_create_mutable (&temp_obstack);
2665 +
2666 +  iter = index->address_table;
2667 +  end = iter + index->address_table_size;
2668 +
2669 +  baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2670 +
2671 +  while (iter < end)
2672 +    {
2673 +      ULONGEST hi, lo, cu_index;
2674 +      lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
2675 +      iter += 8;
2676 +      hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
2677 +      iter += 8;
2678 +      cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE);
2679 +      iter += 4;
2680 +      
2681 +      addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1,
2682 +                        dwarf2_per_objfile->all_comp_units[cu_index]);
2683 +    }
2684 +
2685 +  objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map,
2686 +                                                   &objfile->objfile_obstack);
2687 +  do_cleanups (cleanup);
2688 +}
2689 +
2690 +/* The hash function for strings in the mapped index.  This is the
2691 +   same as the hashtab.c hash function, but we keep a separate copy to
2692 +   maintain control over the implementation.  This is necessary
2693 +   because the hash function is tied to the format of the mapped index
2694 +   file.  */
2695 +static hashval_t
2696 +mapped_index_string_hash (const void *p)
2697 +{
2698 +  const unsigned char *str = (const unsigned char *) p;
2699 +  hashval_t r = 0;
2700 +  unsigned char c;
2701 +
2702 +  while ((c = *str++) != 0)
2703 +    r = r * 67 + c - 113;
2704 +
2705 +  return r;
2706 +}
2707 +
2708 +/* Find a slot in the mapped index INDEX for the object named NAME.
2709 +   If NAME is found, set *VEC_OUT to point to the CU vector in the
2710 +   constant pool and return 1.  If NAME cannot be found, return 0.  */
2711 +static int
2712 +find_slot_in_mapped_hash (struct mapped_index *index, const char *name,
2713 +                         offset_type **vec_out)
2714 +{
2715 +  offset_type hash = mapped_index_string_hash (name);
2716 +  offset_type slot, step;
2717 +
2718 +  slot = hash & (index->index_table_slots - 1);
2719 +  step = ((hash * 17) & (index->index_table_slots - 1)) | 1;
2720 +
2721 +  for (;;)
2722 +    {
2723 +      /* Convert a slot number to an offset into the table.  */
2724 +      offset_type i = 2 * slot;
2725 +      const char *str;
2726 +      if (index->index_table[i] == 0 && index->index_table[i + 1] == 0)
2727 +       return 0;
2728 +
2729 +      str = index->constant_pool + MAYBE_SWAP (index->index_table[i]);
2730 +      if (!strcmp (name, str))
2731 +       {
2732 +         *vec_out = (offset_type *) (index->constant_pool
2733 +                                     + MAYBE_SWAP (index->index_table[i + 1]));
2734 +         return 1;
2735 +       }
2736 +
2737 +      slot = (slot + step) & (index->index_table_slots - 1);
2738 +    }
2739 +}
2740 +
2741 +/* Read the index file.  If everything went ok, initialize the "quick"
2742 +   elements of all the CUs and return 1.  Otherwise, return 0.  */
2743 +static int
2744 +dwarf2_read_index (struct objfile *objfile)
2745 +{
2746 +  char *addr;
2747 +  struct mapped_index *map;
2748 +  offset_type *metadata;
2749 +  const gdb_byte *cu_list;
2750 +  offset_type cu_list_elements;
2751 +
2752 +  if (dwarf2_per_objfile->gdb_index.asection == NULL
2753 +      || dwarf2_per_objfile->gdb_index.size == 0)
2754 +    return 0;
2755 +  dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index);
2756 +
2757 +  addr = dwarf2_per_objfile->gdb_index.buffer;
2758 +  /* Version check.  */
2759 +  if (MAYBE_SWAP (*(offset_type *) addr) != 1)
2760 +    return 0;
2761 +
2762 +  map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index);
2763 +  map->total_size = dwarf2_per_objfile->gdb_index.size;
2764 +
2765 +  metadata = (offset_type *) (addr + sizeof (offset_type));
2766 +  cu_list = addr + MAYBE_SWAP (metadata[0]);
2767 +  cu_list_elements = ((MAYBE_SWAP (metadata[1]) - MAYBE_SWAP (metadata[0]))
2768 +                     / 8);
2769 +  map->address_table = addr + MAYBE_SWAP (metadata[1]);
2770 +  map->address_table_size = (MAYBE_SWAP (metadata[2])
2771 +                            - MAYBE_SWAP (metadata[1]));
2772 +  map->index_table = (offset_type *) (addr + MAYBE_SWAP (metadata[2]));
2773 +  map->index_table_slots = ((MAYBE_SWAP (metadata[3])
2774 +                            - MAYBE_SWAP (metadata[2]))
2775 +                           / (2 * sizeof (offset_type)));
2776 +  map->constant_pool = addr + MAYBE_SWAP (metadata[3]);
2777 +
2778 +  if (!create_cus_from_index (objfile, map, cu_list, cu_list_elements))
2779 +    return 0;
2780 +
2781 +  create_addrmap_from_index (objfile, map);
2782 +
2783 +  dwarf2_per_objfile->index_table = map;
2784 +  dwarf2_per_objfile->using_index = 1;
2785 +
2786 +  return 1;
2787 +}
2788 +
2789 +/* A helper for the "quick" functions which sets the global
2790 +   dwarf2_per_objfile according to OBJFILE.  */
2791 +static void
2792 +dw2_setup (struct objfile *objfile)
2793 +{
2794 +  dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
2795 +  gdb_assert (dwarf2_per_objfile);
2796 +}
2797 +
2798 +/* A helper for the "quick" functions which attempts to read the line
2799 +   table for THIS_CU.  */
2800 +static void
2801 +dw2_require_line_header (struct objfile *objfile,
2802 +                        struct dwarf2_per_cu_data *this_cu)
2803 +{
2804 +  bfd *abfd = objfile->obfd;
2805 +  struct line_header *lh = NULL;
2806 +  struct attribute *attr;
2807 +  struct cleanup *cleanups;
2808 +  struct die_info *comp_unit_die;
2809 +  gdb_byte *beg_of_comp_unit, *info_ptr, *buffer;
2810 +  int has_children, i;
2811 +  struct dwarf2_cu cu;
2812 +  unsigned int bytes_read, buffer_size;
2813 +  struct die_reader_specs reader_specs;
2814 +  char *name, *comp_dir;
2815 +
2816 +  if (this_cu->v.quick->read_lines)
2817 +    return;
2818 +  this_cu->v.quick->read_lines = 1;
2819 +
2820 +  memset (&cu, 0, sizeof (cu));
2821 +  cu.objfile = objfile;
2822 +  obstack_init (&cu.comp_unit_obstack);
2823 +
2824 +  cleanups = make_cleanup (free_stack_comp_unit, &cu);
2825 +
2826 +  dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
2827 +  buffer_size = dwarf2_per_objfile->info.size;
2828 +  buffer = dwarf2_per_objfile->info.buffer;
2829 +  info_ptr = buffer + this_cu->offset;
2830 +  beg_of_comp_unit = info_ptr;
2831 +
2832 +  info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
2833 +                                         buffer, buffer_size,
2834 +                                         abfd);
2835 +
2836 +  /* Complete the cu_header.  */
2837 +  cu.header.offset = beg_of_comp_unit - buffer;
2838 +  cu.header.first_die_offset = info_ptr - beg_of_comp_unit;
2839 +
2840 +  this_cu->cu = &cu;
2841 +  cu.per_cu = this_cu;
2842 +
2843 +  dwarf2_read_abbrevs (abfd, &cu);
2844 +  make_cleanup (dwarf2_free_abbrev_table, &cu);
2845 +
2846 +  if (this_cu->from_debug_types)
2847 +    info_ptr += 8 /*signature*/ + cu.header.offset_size;
2848 +  init_cu_die_reader (&reader_specs, &cu);
2849 +  info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
2850 +                           &has_children);
2851 +
2852 +  attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, &cu);
2853 +  if (attr)
2854 +    {
2855 +      unsigned int line_offset = DW_UNSND (attr);
2856 +      lh = dwarf_decode_line_header (line_offset, abfd, &cu);
2857 +    }
2858 +  if (lh == NULL)
2859 +    {
2860 +      do_cleanups (cleanups);
2861 +      return;
2862 +    }
2863 +
2864 +  find_file_and_directory (comp_unit_die, &cu, &name, &comp_dir);
2865 +
2866 +  this_cu->v.quick->lines = lh;
2867 +
2868 +  this_cu->v.quick->file_names
2869 +    = obstack_alloc (&objfile->objfile_obstack,
2870 +                    lh->num_file_names * sizeof (char *));
2871 +  for (i = 0; i < lh->num_file_names; ++i)
2872 +    this_cu->v.quick->file_names[i] = file_full_name (i + 1, lh, comp_dir);
2873 +
2874 +  do_cleanups (cleanups);
2875 +}
2876 +
2877 +/* A helper for the "quick" functions which computes and caches the
2878 +   real path for a given file name from the line table.
2879 +   dw2_require_line_header must have been called before this is
2880 +   invoked.  */
2881 +static const char *
2882 +dw2_require_full_path (struct objfile *objfile,
2883 +                      struct dwarf2_per_cu_data *cu,
2884 +                      int index)
2885 +{
2886 +  if (!cu->v.quick->full_names)
2887 +    cu->v.quick->full_names
2888 +      = OBSTACK_CALLOC (&objfile->objfile_obstack,
2889 +                       cu->v.quick->lines->num_file_names,
2890 +                       sizeof (char *));
2891 +
2892 +  if (!cu->v.quick->full_names[index])
2893 +    cu->v.quick->full_names[index]
2894 +      = gdb_realpath (cu->v.quick->file_names[index]);
2895 +
2896 +  return cu->v.quick->full_names[index];
2897 +}
2898 +
2899 +static struct symtab *
2900 +dw2_find_last_source_symtab (struct objfile *objfile)
2901 +{
2902 +  int index;
2903 +  dw2_setup (objfile);
2904 +  index = dwarf2_per_objfile->n_comp_units - 1;
2905 +  return dw2_instantiate_symtab (objfile,
2906 +                                dwarf2_per_objfile->all_comp_units[index]);
2907 +}
2908 +
2909 +static void
2910 +dw2_forget_cached_source_info (struct objfile *objfile)
2911 +{
2912 +  int i;
2913 +
2914 +  dw2_setup (objfile);
2915 +  for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
2916 +    {
2917 +      struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
2918 +
2919 +      if (cu->v.quick->full_names)
2920 +       {
2921 +         int j;
2922 +
2923 +         for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
2924 +           xfree ((void *) cu->v.quick->full_names[j]);
2925 +       }
2926 +    }
2927 +}
2928 +
2929 +static int
2930 +dw2_lookup_symtab (struct objfile *objfile, const char *name,
2931 +                  const char *full_path, const char *real_path,
2932 +                  struct symtab **result)
2933 +{
2934 +  int i;
2935 +  int check_basename = lbasename (name) == name;
2936 +  struct dwarf2_per_cu_data *base_cu = NULL;
2937 +
2938 +  dw2_setup (objfile);
2939 +  for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
2940 +    {
2941 +      int j;
2942 +      struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
2943 +
2944 +      if (cu->v.quick->symtab)
2945 +       continue;
2946 +
2947 +      dw2_require_line_header (objfile, cu);
2948 +      if (!cu->v.quick->lines)
2949 +       continue;
2950 +
2951 +      for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
2952 +       {
2953 +         const char *this_name = cu->v.quick->file_names[j];
2954 +
2955 +         if (FILENAME_CMP (name, this_name) == 0)
2956 +           {
2957 +             *result = dw2_instantiate_symtab (objfile, cu);
2958 +             return 1;
2959 +           }
2960 +
2961 +         if (check_basename && ! base_cu
2962 +             && FILENAME_CMP (lbasename (this_name), name) == 0)
2963 +           base_cu = cu;
2964 +
2965 +         if (full_path != NULL)
2966 +           {
2967 +             const char *this_full_name = dw2_require_full_path (objfile,
2968 +                                                                 cu, j);
2969 +
2970 +             if (this_full_name
2971 +                 && FILENAME_CMP (full_path, this_full_name) == 0)
2972 +               {
2973 +                 *result = dw2_instantiate_symtab (objfile, cu);
2974 +                 return 1;
2975 +               }
2976 +           }
2977 +
2978 +         if (real_path != NULL)
2979 +           {
2980 +             const char *this_full_name = dw2_require_full_path (objfile,
2981 +                                                                 cu, j);
2982 +
2983 +             if (this_full_name != NULL)
2984 +               {
2985 +                 char *rp = gdb_realpath (this_full_name);
2986 +                 if (rp != NULL && FILENAME_CMP (real_path, rp) == 0)
2987 +                   {
2988 +                     xfree (rp);
2989 +                     *result = dw2_instantiate_symtab (objfile, cu);
2990 +                     return 1;
2991 +                   }
2992 +                 xfree (rp);
2993 +               }
2994 +           }
2995 +       }
2996 +    }
2997 +
2998 +  if (base_cu)
2999 +    {
3000 +      *result = dw2_instantiate_symtab (objfile, base_cu);
3001 +      return 1;
3002 +    }
3003 +
3004 +  return 0;
3005 +}
3006 +
3007 +static struct symtab *
3008 +dw2_lookup_symbol (struct objfile *objfile, int block_index,
3009 +                  const char *name, domain_enum domain)
3010 +{
3011 +  /* We do all the work in the pre_expand_symtabs_matching hook
3012 +     instead.  */
3013 +  return NULL;
3014 +}
3015 +
3016 +/* A helper function that expands all symtabs that hold an object
3017 +   named NAME.  */
3018 +static void
3019 +dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name)
3020 +{
3021 +  dw2_setup (objfile);
3022 +
3023 +  if (dwarf2_per_objfile->index_table)
3024 +    {
3025 +      offset_type *vec;
3026 +
3027 +      if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
3028 +                                   name, &vec))
3029 +       {
3030 +         offset_type i, len = MAYBE_SWAP (*vec);
3031 +         for (i = 0; i < len; ++i)
3032 +           {
3033 +             offset_type cu_index = MAYBE_SWAP (vec[i + 1]);
3034 +             struct dwarf2_per_cu_data *cu;
3035 +             cu = dwarf2_per_objfile->all_comp_units[cu_index];
3036 +             dw2_instantiate_symtab (objfile, cu);
3037 +           }
3038 +       }
3039 +    }
3040 +}
3041 +
3042 +static void
3043 +dw2_pre_expand_symtabs_matching (struct objfile *objfile,
3044 +                                int kind, const char *name,
3045 +                                domain_enum domain)
3046 +{
3047 +  dw2_do_expand_symtabs_matching (objfile, name);
3048 +}
3049 +
3050 +static void
3051 +dw2_print_stats (struct objfile *objfile)
3052 +{
3053 +  int i, count;
3054 +
3055 +  dw2_setup (objfile);
3056 +  count = 0;
3057 +  for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
3058 +    {
3059 +      struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
3060 +
3061 +      if (!cu->v.quick->symtab)
3062 +       ++count;
3063 +    }
3064 +  printf_filtered (_("  Number of unread CUs: %d\n"), count);
3065 +}
3066 +
3067 +static void
3068 +dw2_dump (struct objfile *objfile)
3069 +{
3070 +  /* Nothing worth printing.  */
3071 +}
3072 +
3073 +static void
3074 +dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets,
3075 +             struct section_offsets *delta)
3076 +{
3077 +  /* There's nothing to relocate here.  */
3078 +}
3079 +
3080 +static void
3081 +dw2_expand_symtabs_for_function (struct objfile *objfile,
3082 +                                const char *func_name)
3083 +{
3084 +  dw2_do_expand_symtabs_matching (objfile, func_name);
3085 +}
3086 +
3087 +static void
3088 +dw2_expand_all_symtabs (struct objfile *objfile)
3089 +{
3090 +  int i;
3091 +
3092 +  dw2_setup (objfile);
3093 +  for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
3094 +    {
3095 +      struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
3096 +
3097 +      dw2_instantiate_symtab (objfile, cu);
3098 +    }
3099 +}
3100 +
3101 +static void
3102 +dw2_expand_symtabs_with_filename (struct objfile *objfile,
3103 +                                 const char *filename)
3104 +{
3105 +  int i;
3106 +
3107 +  dw2_setup (objfile);
3108 +  for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
3109 +    {
3110 +      int j;
3111 +      struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
3112 +
3113 +      if (cu->v.quick->symtab)
3114 +       continue;
3115 +
3116 +      dw2_require_line_header (objfile, cu);
3117 +      if (!cu->v.quick->lines)
3118 +       continue;
3119 +
3120 +      for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
3121 +       {
3122 +         const char *this_name = cu->v.quick->file_names[j];
3123 +         if (strcmp (this_name, filename) == 0)
3124 +           {
3125 +             dw2_instantiate_symtab (objfile, cu);
3126 +             break;
3127 +           }
3128 +       }
3129 +    }
3130 +}
3131 +
3132 +static const char *
3133 +dw2_find_symbol_file (struct objfile *objfile, const char *name)
3134 +{
3135 +  struct dwarf2_per_cu_data *cu;
3136 +  offset_type *vec;
3137 +
3138 +  dw2_setup (objfile);
3139 +
3140 +  if (!dwarf2_per_objfile->index_table)
3141 +    return NULL;
3142 +
3143 +  if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
3144 +                                name, &vec))
3145 +    return NULL;
3146 +
3147 +  /* Note that this just looks at the very first one named NAME -- but
3148 +     actually we are looking for a function.  find_main_filename
3149 +     should be rewritten so that it doesn't require a custom hook.  It
3150 +     could just use the ordinary symbol tables.  */
3151 +  /* vec[0] is the length, which must always be >0.  */
3152 +  cu = dwarf2_per_objfile->all_comp_units[MAYBE_SWAP (vec[1])];
3153 +
3154 +  dw2_require_line_header (objfile, cu);
3155 +  if (!cu->v.quick->lines)
3156 +    return NULL;
3157 +
3158 +  return cu->v.quick->file_names[cu->v.quick->lines->num_file_names - 1];
3159 +}
3160 +
3161 +static void
3162 +dw2_map_ada_symtabs (struct objfile *objfile,
3163 +                    int (*wild_match) (const char *, int, const char *),
3164 +                    int (*is_name_suffix) (const char *),
3165 +                    void (*callback) (struct objfile *,
3166 +                                      struct symtab *, void *),
3167 +                    const char *name, int global,
3168 +                    domain_enum namespace, int wild,
3169 +                    void *data)
3170 +{
3171 +  /* For now, we don't support Ada, so this function can't be
3172 +     reached.  */
3173 +  internal_error (__FILE__, __LINE__,
3174 +                 _("map_ada_symtabs called via index method"));
3175 +}
3176 +
3177 +static void
3178 +dw2_expand_symtabs_matching (struct objfile *objfile,
3179 +                            int (*file_matcher) (const char *, void *),
3180 +                            int (*name_matcher) (const char *, void *),
3181 +                            domain_enum kind,
3182 +                            void *data)
3183 +{
3184 +  int i;
3185 +  offset_type iter;
3186 +
3187 +  dw2_setup (objfile);
3188 +  if (!dwarf2_per_objfile->index_table)
3189 +    return;
3190 +
3191 +  for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
3192 +    {
3193 +      int j;
3194 +      struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
3195 +
3196 +      cu->v.quick->mark = 0;
3197 +      if (cu->v.quick->symtab)
3198 +       continue;
3199 +
3200 +      dw2_require_line_header (objfile, cu);
3201 +      if (!cu->v.quick->lines)
3202 +       continue;
3203 +
3204 +      for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
3205 +       {
3206 +         if (file_matcher (cu->v.quick->file_names[j], data))
3207 +           {
3208 +             cu->v.quick->mark = 1;
3209 +             break;
3210 +           }
3211 +       }
3212 +    }
3213 +
3214 +  for (iter = 0;
3215 +       iter < dwarf2_per_objfile->index_table->index_table_slots;
3216 +       ++iter)
3217 +    {
3218 +      offset_type idx = 2 * iter;
3219 +      const char *name;
3220 +      offset_type *vec, vec_len, vec_idx;
3221 +
3222 +      if (dwarf2_per_objfile->index_table->index_table[idx] == 0
3223 +         && dwarf2_per_objfile->index_table->index_table[idx + 1] == 0)
3224 +       continue;
3225 +
3226 +      name = (dwarf2_per_objfile->index_table->constant_pool
3227 +             + dwarf2_per_objfile->index_table->index_table[idx]);
3228 +
3229 +      if (! (*name_matcher) (name, data))
3230 +       continue;
3231 +
3232 +      /* The name was matched, now expand corresponding CUs that were
3233 +        marked.  */
3234 +      vec = (offset_type *) (dwarf2_per_objfile->index_table->constant_pool
3235 +                            + dwarf2_per_objfile->index_table->index_table[idx + 1]);
3236 +      vec_len = MAYBE_SWAP (vec[0]);
3237 +      for (vec_idx = 0; vec_idx < vec_len; ++vec_idx)
3238 +       {
3239 +         struct dwarf2_per_cu_data *cu
3240 +           = dwarf2_per_objfile->all_comp_units[MAYBE_SWAP (vec[vec_idx + 1])];
3241 +         if (cu->v.quick->mark)
3242 +           dw2_instantiate_symtab (objfile, cu);
3243 +       }
3244 +    }
3245 +}
3246 +
3247 +static struct symtab *
3248 +dw2_find_pc_sect_symtab (struct objfile *objfile,
3249 +                        struct minimal_symbol *msymbol,
3250 +                        CORE_ADDR pc,
3251 +                        struct obj_section *section,
3252 +                        int warn_if_readin)
3253 +{
3254 +  struct dwarf2_per_cu_data *data;
3255 +
3256 +  dw2_setup (objfile);
3257 +
3258 +  if (!objfile->psymtabs_addrmap)
3259 +    return NULL;
3260 +
3261 +  data = addrmap_find (objfile->psymtabs_addrmap, pc);
3262 +  if (!data)
3263 +    return NULL;
3264 +
3265 +  if (warn_if_readin && data->v.quick->symtab)
3266 +    warning (_("(Internal error: pc %s in read in CU, but not in symtab.)\n"),
3267 +            paddress (get_objfile_arch (objfile), pc));
3268 +
3269 +  return dw2_instantiate_symtab (objfile, data);
3270 +}
3271 +
3272 +static void
3273 +dw2_map_symbol_names (struct objfile *objfile,
3274 +                     void (*fun) (const char *, void *),
3275 +                     void *data)
3276 +{
3277 +  offset_type iter;
3278 +  dw2_setup (objfile);
3279  
3280 -  if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0)
3281 +  if (!dwarf2_per_objfile->index_table)
3282 +    return;
3283 +
3284 +  for (iter = 0;
3285 +       iter < dwarf2_per_objfile->index_table->index_table_slots;
3286 +       ++iter)
3287      {
3288 -      off_t pg_offset = sectp->filepos & ~(pagesize - 1);
3289 -      size_t map_length = info->size + sectp->filepos - pg_offset;
3290 -      caddr_t retbuf = bfd_mmap (abfd, 0, map_length, PROT_READ,
3291 -                                MAP_PRIVATE, pg_offset);
3292 +      offset_type idx = 2 * iter;
3293 +      const char *name;
3294 +      offset_type *vec, vec_len, vec_idx;
3295  
3296 -      if (retbuf != MAP_FAILED)
3297 -       {
3298 -         info->was_mmapped = 1;
3299 -         info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ;
3300 -#if HAVE_POSIX_MADVISE
3301 -         posix_madvise (retbuf, map_length, POSIX_MADV_WILLNEED);
3302 -#endif
3303 -         return;
3304 -       }
3305 +      if (dwarf2_per_objfile->index_table->index_table[idx] == 0
3306 +         && dwarf2_per_objfile->index_table->index_table[idx + 1] == 0)
3307 +       continue;
3308 +
3309 +      name = (dwarf2_per_objfile->index_table->constant_pool
3310 +             + dwarf2_per_objfile->index_table->index_table[idx]);
3311 +
3312 +      (*fun) (name, data);
3313      }
3314 -#endif
3315 +}
3316  
3317 -  /* If we get here, we are a normal, not-compressed section.  */
3318 -  info->buffer = buf
3319 -    = obstack_alloc (&objfile->objfile_obstack, info->size);
3320 +static void
3321 +dw2_map_symbol_filenames (struct objfile *objfile,
3322 +                         void (*fun) (const char *, const char *, void *),
3323 +                         void *data)
3324 +{
3325 +  int i;
3326  
3327 -  /* When debugging .o files, we may need to apply relocations; see
3328 -     http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
3329 -     We never compress sections in .o files, so we only need to
3330 -     try this when the section is not compressed.  */
3331 -  retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
3332 -  if (retbuf != NULL)
3333 +  dw2_setup (objfile);
3334 +  for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
3335      {
3336 -      info->buffer = retbuf;
3337 -      return;
3338 +      int j;
3339 +      struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
3340 +
3341 +      if (cu->v.quick->symtab)
3342 +       continue;
3343 +
3344 +      dw2_require_line_header (objfile, cu);
3345 +      if (!cu->v.quick->lines)
3346 +       continue;
3347 +
3348 +      for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
3349 +       {
3350 +         const char *this_full_name = dw2_require_full_path (objfile, cu, j);
3351 +         (*fun) (cu->v.quick->file_names[j], this_full_name, data);
3352 +       }
3353      }
3354 +}
3355  
3356 -  if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
3357 -      || bfd_bread (buf, info->size, abfd) != info->size)
3358 -    error (_("Dwarf Error: Can't read DWARF data from '%s'"),
3359 -          bfd_get_filename (abfd));
3360 +static int
3361 +dw2_has_symbols (struct objfile *objfile)
3362 +{
3363 +  return 1;
3364  }
3365  
3366 -/* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
3367 -   SECTION_NAME. */
3368 +const struct quick_symbol_functions dwarf2_gdb_index_functions =
3369 +{
3370 +  dw2_has_symbols,
3371 +  dw2_find_last_source_symtab,
3372 +  dw2_forget_cached_source_info,
3373 +  dw2_lookup_symtab,
3374 +  dw2_lookup_symbol,
3375 +  dw2_pre_expand_symtabs_matching,
3376 +  dw2_print_stats,
3377 +  dw2_dump,
3378 +  dw2_relocate,
3379 +  dw2_expand_symtabs_for_function,
3380 +  dw2_expand_all_symtabs,
3381 +  dw2_expand_symtabs_with_filename,
3382 +  dw2_find_symbol_file,
3383 +  dw2_map_ada_symtabs,
3384 +  dw2_expand_symtabs_matching,
3385 +  dw2_find_pc_sect_symtab,
3386 +  dw2_map_symbol_names,
3387 +  dw2_map_symbol_filenames
3388 +};
3389  
3390 -void
3391 -dwarf2_get_section_info (struct objfile *objfile, const char *section_name,
3392 -                         asection **sectp, gdb_byte **bufp,
3393 -                         bfd_size_type *sizep)
3394 -{
3395 -  struct dwarf2_per_objfile *data
3396 -    = objfile_data (objfile, dwarf2_objfile_data_key);
3397 -  struct dwarf2_section_info *info;
3398 +/* Initialize for reading DWARF for this objfile.  Return 0 if this
3399 +   file will use psymtabs, or 1 if using the GNU index.  */
3400  
3401 -  /* We may see an objfile without any DWARF, in which case we just
3402 -     return nothing.  */
3403 -  if (data == NULL)
3404 +int
3405 +dwarf2_initialize_objfile (struct objfile *objfile)
3406 +{
3407 +  /* If we're about to read full symbols, don't bother with the
3408 +     indices.  In this case we also don't care if some other debug
3409 +     format is making psymtabs, because they are all about to be
3410 +     expanded anyway.  */
3411 +  if ((objfile->flags & OBJF_READNOW))
3412      {
3413 -      *sectp = NULL;
3414 -      *bufp = NULL;
3415 -      *sizep = 0;
3416 -      return;
3417 +      int i;
3418 +
3419 +      dwarf2_per_objfile->using_index = 1;
3420 +      create_all_comp_units (objfile);
3421 +
3422 +      for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
3423 +       {
3424 +         struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
3425 +
3426 +         cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
3427 +                                       struct dwarf2_per_cu_quick_data);
3428 +       }
3429 +
3430 +      /* Return 1 so that gdb sees the "quick" functions.  However,
3431 +        these functions will be no-ops because we will have expanded
3432 +        all symtabs.  */
3433 +      return 1;
3434      }
3435 -  if (section_is_p (section_name, EH_FRAME_SECTION))
3436 -    info = &data->eh_frame;
3437 -  else if (section_is_p (section_name, FRAME_SECTION))
3438 -    info = &data->frame;
3439 -  else
3440 -    gdb_assert (0);
3441  
3442 -  if (info->asection != NULL && info->size != 0 && info->buffer == NULL)
3443 -    /* We haven't read this section in yet.  Do it now.  */
3444 -    dwarf2_read_section (objfile, info);
3445 +  if (dwarf2_read_index (objfile))
3446 +    return 1;
3447  
3448 -  *sectp = info->asection;
3449 -  *bufp = info->buffer;
3450 -  *sizep = info->size;
3451 +  dwarf2_build_psymtabs (objfile);
3452 +  return 0;
3453  }
3454  
3455 +\f
3456 +
3457  /* Build a partial symbol table.  */
3458  
3459  void
3460 @@ -1699,6 +2688,7 @@ create_debug_types_hash_table (struct objfile *objfile)
3461        type_sig->signature = signature;
3462        type_sig->offset = offset;
3463        type_sig->type_offset = type_offset;
3464 +      type_sig->per_cu.objfile = objfile;
3465  
3466        slot = htab_find_slot (types_htab, type_sig, INSERT);
3467        gdb_assert (slot != NULL);
3468 @@ -1897,7 +2887,7 @@ process_psymtab_comp_unit (struct objfile *objfile,
3469    /* Store the function that reads in the rest of the symbol table */
3470    pst->read_symtab = dwarf2_psymtab_to_symtab;
3471  
3472 -  this_cu->psymtab = pst;
3473 +  this_cu->v.psymtab = pst;
3474  
3475    dwarf2_find_base_address (comp_unit_die, &cu);
3476  
3477 @@ -2182,6 +3172,7 @@ create_all_comp_units (struct objfile *objfile)
3478        memset (this_cu, 0, sizeof (*this_cu));
3479        this_cu->offset = offset;
3480        this_cu->length = length + initial_length_size;
3481 +      this_cu->objfile = objfile;
3482  
3483        if (n_comp_units == n_allocated)
3484         {
3485 @@ -2613,7 +3604,7 @@ add_partial_subprogram (struct partial_die_info *pdi,
3486               addrmap_set_empty (objfile->psymtabs_addrmap,
3487                                  pdi->lowpc + baseaddr,
3488                                  pdi->highpc - 1 + baseaddr,
3489 -                                cu->per_cu->psymtab);
3490 +                                cu->per_cu->v.psymtab);
3491             }
3492            if (!pdi->is_declaration)
3493             /* Ignore subprogram DIEs that do not have a name, they are
3494 @@ -2885,7 +3876,6 @@ locate_pdi_sibling (struct partial_die_info *orig_pdi,
3495  static void
3496  dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
3497  {
3498 -  /* FIXME: This is barely more than a stub.  */
3499    if (pst != NULL)
3500      {
3501        if (pst->readin)
3502 @@ -2958,7 +3948,9 @@ process_queue (struct objfile *objfile)
3503       may load a new CU, adding it to the end of the queue.  */
3504    for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item)
3505      {
3506 -      if (item->per_cu->psymtab && !item->per_cu->psymtab->readin)
3507 +      if (dwarf2_per_objfile->using_index
3508 +         ? !item->per_cu->v.quick->symtab
3509 +         : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin))
3510         process_full_comp_unit (item->per_cu);
3511  
3512        item->per_cu->queued = 0;
3513 @@ -3035,22 +4027,7 @@ psymtab_to_symtab_1 (struct partial_symtab *pst)
3514        return;
3515      }
3516  
3517 -  back_to = make_cleanup (dwarf2_release_queue, NULL);
3518 -
3519 -  queue_comp_unit (per_cu, pst->objfile);
3520 -
3521 -  if (per_cu->from_debug_types)
3522 -    read_signatured_type_at_offset (pst->objfile, per_cu->offset);
3523 -  else
3524 -    load_full_comp_unit (per_cu, pst->objfile);
3525 -
3526 -  process_queue (pst->objfile);
3527 -
3528 -  /* Age the cache, releasing compilation units that have not
3529 -     been used recently.  */
3530 -  age_cached_comp_units ();
3531 -
3532 -  do_cleanups (back_to);
3533 +  dw2_do_instantiate_symtab (pst->objfile, per_cu);
3534  }
3535  
3536  /* Load the DIEs associated with PER_CU into memory.  */
3537 @@ -3130,9 +4107,8 @@ load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
3538  static void
3539  process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
3540  {
3541 -  struct partial_symtab *pst = per_cu->psymtab;
3542    struct dwarf2_cu *cu = per_cu->cu;
3543 -  struct objfile *objfile = pst->objfile;
3544 +  struct objfile *objfile = per_cu->objfile;
3545    CORE_ADDR lowpc, highpc;
3546    struct symtab *symtab;
3547    struct cleanup *back_to;
3548 @@ -3165,8 +4141,15 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
3549      {
3550        symtab->language = cu->language;
3551      }
3552 -  pst->symtab = symtab;
3553 -  pst->readin = 1;
3554 +
3555 +  if (dwarf2_per_objfile->using_index)
3556 +    per_cu->v.quick->symtab = symtab;
3557 +  else
3558 +    {
3559 +      struct partial_symtab *pst = per_cu->v.psymtab;
3560 +      pst->symtab = symtab;
3561 +      pst->readin = 1;
3562 +    }
3563  
3564    do_cleanups (back_to);
3565  }
3566 @@ -3557,6 +4540,46 @@ free_cu_line_header (void *arg)
3567  }
3568  
3569  static void
3570 +find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu,
3571 +                        char **name, char **comp_dir)
3572 +{
3573 +  struct attribute *attr;
3574 +
3575 +  *name = NULL;
3576 +  *comp_dir = NULL;
3577 +
3578 +  /* Find the filename.  Do not use dwarf2_name here, since the filename
3579 +     is not a source language identifier.  */
3580 +  attr = dwarf2_attr (die, DW_AT_name, cu);
3581 +  if (attr)
3582 +    {
3583 +      *name = DW_STRING (attr);
3584 +    }
3585 +
3586 +  attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
3587 +  if (attr)
3588 +    *comp_dir = DW_STRING (attr);
3589 +  else if (*name != NULL && IS_ABSOLUTE_PATH (*name))
3590 +    {
3591 +      *comp_dir = ldirname (*name);
3592 +      if (*comp_dir != NULL)
3593 +       make_cleanup (xfree, *comp_dir);
3594 +    }
3595 +  if (*comp_dir != NULL)
3596 +    {
3597 +      /* Irix 6.2 native cc prepends <machine>.: to the compilation
3598 +        directory, get rid of it.  */
3599 +      char *cp = strchr (*comp_dir, ':');
3600 +
3601 +      if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/')
3602 +       *comp_dir = cp + 1;
3603 +    }
3604 +
3605 +  if (*name == NULL)
3606 +    *name = "<unknown>";
3607 +}
3608 +
3609 +static void
3610  read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
3611  {
3612    struct objfile *objfile = cu->objfile;
3613 @@ -3582,35 +4605,7 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
3614    lowpc += baseaddr;
3615    highpc += baseaddr;
3616  
3617 -  /* Find the filename.  Do not use dwarf2_name here, since the filename
3618 -     is not a source language identifier.  */
3619 -  attr = dwarf2_attr (die, DW_AT_name, cu);
3620 -  if (attr)
3621 -    {
3622 -      name = DW_STRING (attr);
3623 -    }
3624 -
3625 -  attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
3626 -  if (attr)
3627 -    comp_dir = DW_STRING (attr);
3628 -  else if (name != NULL && IS_ABSOLUTE_PATH (name))
3629 -    {
3630 -      comp_dir = ldirname (name);
3631 -      if (comp_dir != NULL)
3632 -       make_cleanup (xfree, comp_dir);
3633 -    }
3634 -  if (comp_dir != NULL)
3635 -    {
3636 -      /* Irix 6.2 native cc prepends <machine>.: to the compilation
3637 -        directory, get rid of it.  */
3638 -      char *cp = strchr (comp_dir, ':');
3639 -
3640 -      if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/')
3641 -       comp_dir = cp + 1;
3642 -    }
3643 -
3644 -  if (name == NULL)
3645 -    name = "<unknown>";
3646 +  find_file_and_directory (die, cu, &name, &comp_dir);
3647  
3648    attr = dwarf2_attr (die, DW_AT_language, cu);
3649    if (attr)
3650 @@ -5529,6 +6524,29 @@ process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
3651    new_symbol (die, this_type, cu);
3652  }
3653  
3654 +/* Create a new array dimension referencing its target type TYPE.
3655 +
3656 +   Multidimensional arrays are internally represented as a stack of
3657 +   singledimensional arrays being referenced by their TYPE_TARGET_TYPE.  */
3658 +
3659 +static struct type *
3660 +create_single_array_dimension (struct type *type, struct type *range_type,
3661 +                              struct die_info *die, struct dwarf2_cu *cu)
3662 +{
3663 +  type = create_array_type (NULL, type, range_type);
3664 +
3665 +  /* These generic type attributes need to be fetched by
3666 +     evaluate_subexp_standard <multi_f77_subscript>'s call of
3667 +     value_subscripted_rvalue only for the innermost array type.  */
3668 +  fetch_die_type_attrs (die, type, cu);
3669 +
3670 +  /* These generic type attributes are checked for allocated/associated
3671 +     validity while accessing FIELD_LOC_KIND_DWARF_BLOCK.  */
3672 +  fetch_die_type_attrs (die, range_type, cu);
3673 +
3674 +  return type;
3675 +}
3676 +
3677  /* Extract all information from a DW_TAG_array_type DIE and put it in
3678     the DIE's type field.  For now, this only handles one dimensional
3679     arrays.  */
3680 @@ -5542,7 +6560,7 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
3681    struct type *element_type, *range_type, *index_type;
3682    struct type **range_types = NULL;
3683    struct attribute *attr;
3684 -  int ndim = 0;
3685 +  int ndim = 0, i;
3686    struct cleanup *back_to;
3687    char *name;
3688  
3689 @@ -5595,17 +6613,11 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
3690    type = element_type;
3691  
3692    if (read_array_order (die, cu) == DW_ORD_col_major)
3693 -    {
3694 -      int i = 0;
3695 -
3696 -      while (i < ndim)
3697 -       type = create_array_type (NULL, type, range_types[i++]);
3698 -    }
3699 -  else
3700 -    {
3701 -      while (ndim-- > 0)
3702 -       type = create_array_type (NULL, type, range_types[ndim]);
3703 -    }
3704 +    for (i = 0; i < ndim; i++)
3705 +      type = create_single_array_dimension (type, range_types[i], die, cu);
3706 +  else /* (read_array_order (die, cu) == DW_ORD_row_major) */
3707 +    for (i = ndim - 1; i >= 0; i--)
3708 +      type = create_single_array_dimension (type, range_types[i], die, cu);
3709  
3710    /* Understand Dwarf2 support for vector types (like they occur on
3711       the PowerPC w/ AltiVec).  Gcc just adds another attribute to the
3712 @@ -6059,29 +7071,114 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
3713    struct gdbarch *gdbarch = get_objfile_arch (objfile);
3714    struct type *type, *range_type, *index_type, *char_type;
3715    struct attribute *attr;
3716 -  unsigned int length;
3717 +  int length;
3718 +
3719 +  index_type = objfile_type (objfile)->builtin_int;
3720 +  /* RANGE_TYPE is allocated from OBJFILE, not as a permanent type.  */
3721 +  range_type = alloc_type (objfile);
3722 +  /* LOW_BOUND and HIGH_BOUND are set for real below.  */
3723 +  range_type = create_range_type (range_type, index_type, 0, -1);
3724 +
3725 +  /* C/C++ should probably have the low bound 0 but C/C++ does not use
3726 +     DW_TAG_string_type.  */
3727 +  TYPE_LOW_BOUND (range_type) = 1;
3728  
3729    attr = dwarf2_attr (die, DW_AT_string_length, cu);
3730 -  if (attr)
3731 -    {
3732 -      length = DW_UNSND (attr);
3733 +  if (attr && attr_form_is_block (attr))
3734 +    {
3735 +      /* Security check for a size overflow.  */
3736 +      if (DW_BLOCK (attr)->size + 2 < DW_BLOCK (attr)->size)
3737 +       TYPE_HIGH_BOUND (range_type) = 1;
3738 +      /* Extend the DWARF block by a new DW_OP_deref/DW_OP_deref_size
3739 +        instruction as DW_AT_string_length specifies the length location, not
3740 +        its value.  */
3741 +      else
3742 +       {
3743 +         struct dwarf2_locexpr_baton *length_baton = NULL;
3744 +         struct dwarf_block *blk = DW_BLOCK (attr);
3745 +
3746 +         /* Turn any single DW_OP_reg* into DW_OP_breg*(0) but clearing
3747 +            DW_OP_deref* in such case.  */
3748 +
3749 +         if (blk->size == 1 && blk->data[0] >= DW_OP_reg0
3750 +             && blk->data[0] <= DW_OP_reg31)
3751 +           length_baton = dwarf2_attr_to_locexpr_baton (attr, cu);
3752 +         else if (blk->size > 1 && blk->data[0] == DW_OP_regx)
3753 +           {
3754 +             ULONGEST ulongest;
3755 +             const gdb_byte *end;
3756 +
3757 +             end = read_uleb128 (&blk->data[1], &blk->data[blk->size],
3758 +                                 &ulongest);
3759 +             if (end == &blk->data[blk->size])
3760 +               length_baton = dwarf2_attr_to_locexpr_baton (attr, cu);
3761 +           }
3762 +
3763 +         if (length_baton == NULL)
3764 +           {
3765 +             struct attribute *size_attr;
3766 +             gdb_byte *data;
3767 +
3768 +             length_baton = obstack_alloc (&cu->comp_unit_obstack,
3769 +                                           sizeof (*length_baton));
3770 +             length_baton->per_cu = cu->per_cu;
3771 +             length_baton->size = DW_BLOCK (attr)->size + 2;
3772 +             data = obstack_alloc (&cu->comp_unit_obstack,
3773 +                                   length_baton->size);
3774 +             length_baton->data = data;
3775 +             memcpy (data, DW_BLOCK (attr)->data, DW_BLOCK (attr)->size);
3776 +
3777 +             /* DW_AT_BYTE_SIZE existing together with DW_AT_STRING_LENGTH
3778 +                specifies the size of an integer to fetch.  */
3779 +             size_attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3780 +             if (size_attr)
3781 +               {
3782 +                 data[DW_BLOCK (attr)->size] = DW_OP_deref_size;
3783 +                 data[DW_BLOCK (attr)->size + 1] = DW_UNSND (size_attr);
3784 +                 if (data[DW_BLOCK (attr)->size + 1] != DW_UNSND (size_attr))
3785 +                   complaint (&symfile_complaints,
3786 +                              _("DW_AT_string_length's DW_AT_byte_size "
3787 +                                "integer exceeds the byte size storage"));
3788 +               }
3789 +             else
3790 +               {
3791 +                 data[DW_BLOCK (attr)->size] = DW_OP_deref;
3792 +                 data[DW_BLOCK (attr)->size + 1] = DW_OP_nop;
3793 +               }
3794 +           }
3795 +
3796 +         TYPE_RANGE_DATA (range_type)->high.kind
3797 +           = RANGE_BOUND_KIND_DWARF_BLOCK;
3798 +         TYPE_RANGE_DATA (range_type)->high.u.dwarf_block = length_baton;
3799 +         TYPE_DYNAMIC (range_type) = 1;
3800 +       }
3801      }
3802    else
3803      {
3804 -      /* check for the DW_AT_byte_size attribute */
3805 +      if (attr && attr_form_is_constant (attr))
3806 +       {
3807 +         /* We currently do not support a constant address where the location
3808 +            should be read from - attr_form_is_block is expected instead.  See
3809 +            DWARF for the DW_AT_STRING_LENGTH vs. DW_AT_BYTE_SIZE difference.
3810 +            */
3811 +         /* PASSTHRU */
3812 +       }
3813 +
3814        attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3815 -      if (attr)
3816 -        {
3817 -          length = DW_UNSND (attr);
3818 -        }
3819 +      if (attr && attr_form_is_block (attr))
3820 +       {
3821 +         TYPE_RANGE_DATA (range_type)->high.kind
3822 +           = RANGE_BOUND_KIND_DWARF_BLOCK;
3823 +         TYPE_RANGE_DATA (range_type)->high.u.dwarf_block =
3824 +                                       dwarf2_attr_to_locexpr_baton (attr, cu);
3825 +         TYPE_DYNAMIC (range_type) = 1;
3826 +       }
3827 +      else if (attr && attr_form_is_constant (attr))
3828 +       TYPE_HIGH_BOUND (range_type) = dwarf2_get_attr_constant_value (attr, 0);
3829        else
3830 -        {
3831 -          length = 1;
3832 -        }
3833 +       TYPE_HIGH_BOUND (range_type) = 1;
3834      }
3835  
3836 -  index_type = objfile_type (objfile)->builtin_int;
3837 -  range_type = create_range_type (NULL, index_type, 1, length);
3838    char_type = language_string_char_type (cu->language_defn, gdbarch);
3839    type = create_string_type (NULL, char_type, range_type);
3840  
3841 @@ -6324,60 +7421,136 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
3842    struct type *base_type;
3843    struct type *range_type;
3844    struct attribute *attr;
3845 -  LONGEST low = 0;
3846 -  LONGEST high = -1;
3847 +  LONGEST low;
3848    char *name;
3849    LONGEST negative_mask;
3850  
3851    base_type = die_type (die, cu);
3852 +  /* Preserve BASE_TYPE's original type, just set its LENGTH.  */
3853 +  check_typedef (base_type);
3854  
3855    /* The die_type call above may have already set the type for this DIE.  */
3856    range_type = get_die_type (die, cu);
3857    if (range_type)
3858      return range_type;
3859  
3860 -  if (cu->language == language_fortran)
3861 -    {
3862 -      /* FORTRAN implies a lower bound of 1, if not given.  */
3863 -      low = 1;
3864 -    }
3865 +  /* LOW_BOUND and HIGH_BOUND are set for real below.  */
3866 +  range_type = create_range_type (NULL, base_type, 0, -1);
3867 +
3868 +  negative_mask = 
3869 +    (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
3870 +
3871 +  /* Exclude language_ada from any TYPE_DYNAMIC constructs below.  GDB Ada
3872 +     supports implements the dynamic bounds in a non-DWARF way and the
3873 +     existing DWARF dynamic bounds are invalid, leading to memory access
3874 +     errors.  */
3875  
3876 -  /* FIXME: For variable sized arrays either of these could be
3877 -     a variable rather than a constant value.  We'll allow it,
3878 -     but we don't know how to handle it.  */
3879    attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
3880 -  if (attr)
3881 -    low = dwarf2_get_attr_constant_value (attr, 0);
3882 +  if (attr && attr_form_is_block (attr) && cu->language != language_ada)
3883 +    {
3884 +      TYPE_RANGE_DATA (range_type)->low.kind = RANGE_BOUND_KIND_DWARF_BLOCK;
3885 +      TYPE_RANGE_DATA (range_type)->low.u.dwarf_block =
3886 +                                       dwarf2_attr_to_locexpr_baton (attr, cu);
3887 +      TYPE_DYNAMIC (range_type) = 1;
3888 +      /* For setting a default if DW_AT_UPPER_BOUND would be missing.  */
3889 +      low = 0;
3890 +    }
3891 +  else if (attr && is_ref_attr (attr) && cu->language != language_ada)
3892 +    {
3893 +      struct die_info *target_die;
3894 +      struct dwarf2_cu *target_cu = cu;
3895 +      struct attribute *target_loc_attr;
3896 +
3897 +      target_die = follow_die_ref_or_sig (die, attr, &target_cu);
3898 +      gdb_assert (target_cu->objfile == cu->objfile);
3899 +      target_loc_attr = dwarf2_attr (target_die, DW_AT_location, target_cu);
3900 +
3901 +      TYPE_RANGE_DATA (range_type)->low.kind = RANGE_BOUND_KIND_DWARF_LOCLIST;
3902 +      TYPE_RANGE_DATA (range_type)->low.u.dwarf_loclist.loclist
3903 +        = dwarf2_attr_to_loclist_baton (target_loc_attr, target_cu);
3904 +      TYPE_RANGE_DATA (range_type)->low.u.dwarf_loclist.type
3905 +        = die_type (target_die, target_cu);
3906 +      TYPE_DYNAMIC (range_type) = 1;
3907 +      /* For setting a default if DW_AT_UPPER_BOUND would be missing.  */
3908 +      low = 0;
3909 +    }
3910 +  else
3911 +    {
3912 +      if (attr && attr_form_is_constant (attr))
3913 +       low = dwarf2_get_attr_constant_value (attr, 0);
3914 +      else
3915 +       {
3916 +         if (cu->language == language_fortran)
3917 +           {
3918 +             /* FORTRAN implies a lower bound of 1, if not given.  */
3919 +             low = 1;
3920 +           }
3921 +         else
3922 +           {
3923 +             /* According to DWARF we should assume the value 0 only for
3924 +                LANGUAGE_C and LANGUAGE_CPLUS.  */
3925 +             low = 0;
3926 +           }
3927 +       }
3928 +      if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
3929 +       low |= negative_mask;
3930 +      TYPE_LOW_BOUND (range_type) = low;
3931 +      if (low >= 0)
3932 +       TYPE_UNSIGNED (range_type) = 1;
3933 +    }
3934  
3935    attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
3936 -  if (attr)
3937 +  if (!attr || (!attr_form_is_block (attr) && !attr_form_is_constant (attr)
3938 +               && !is_ref_attr (attr)))
3939      {
3940 -      if (attr->form == DW_FORM_block1 || is_ref_attr (attr))
3941 -        {
3942 -          /* GCC encodes arrays with unspecified or dynamic length
3943 -             with a DW_FORM_block1 attribute or a reference attribute.
3944 -             FIXME: GDB does not yet know how to handle dynamic
3945 -             arrays properly, treat them as arrays with unspecified
3946 -             length for now.
3947 -
3948 -             FIXME: jimb/2003-09-22: GDB does not really know
3949 -             how to handle arrays of unspecified length
3950 -             either; we just represent them as zero-length
3951 -             arrays.  Choose an appropriate upper bound given
3952 -             the lower bound we've computed above.  */
3953 -          high = low - 1;
3954 -        }
3955 -      else
3956 -        high = dwarf2_get_attr_constant_value (attr, 1);
3957 +      attr = dwarf2_attr (die, DW_AT_count, cu);
3958 +      /* It does not hurt but it is needlessly ineffective in check_typedef.  */
3959 +      if (attr && (attr_form_is_block (attr) || attr_form_is_constant (attr)))
3960 +       {
3961 +         TYPE_RANGE_HIGH_BOUND_IS_COUNT (range_type) = 1;
3962 +         TYPE_DYNAMIC (range_type) = 1;
3963 +       }
3964 +      /* Pass it now as the regular DW_AT_upper_bound.  */
3965 +    }
3966 +
3967 +  if (attr && attr_form_is_block (attr) && cu->language != language_ada)
3968 +    {
3969 +      TYPE_RANGE_DATA (range_type)->high.kind = RANGE_BOUND_KIND_DWARF_BLOCK;
3970 +      TYPE_RANGE_DATA (range_type)->high.u.dwarf_block =
3971 +                                       dwarf2_attr_to_locexpr_baton (attr, cu);
3972 +      TYPE_DYNAMIC (range_type) = 1;
3973 +    }
3974 +  else if (attr && is_ref_attr (attr) && cu->language != language_ada)
3975 +    {
3976 +      struct die_info *target_die;
3977 +      struct dwarf2_cu *target_cu = cu;
3978 +      struct attribute *target_loc_attr;
3979 +
3980 +      target_die = follow_die_ref_or_sig (die, attr, &target_cu);
3981 +      gdb_assert (target_cu->objfile == cu->objfile);
3982 +      target_loc_attr = dwarf2_attr (target_die, DW_AT_location, target_cu);
3983 +
3984 +      TYPE_RANGE_DATA (range_type)->high.kind = RANGE_BOUND_KIND_DWARF_LOCLIST;
3985 +      TYPE_RANGE_DATA (range_type)->high.u.dwarf_loclist.loclist
3986 +        = dwarf2_attr_to_loclist_baton (target_loc_attr, target_cu);
3987 +      TYPE_RANGE_DATA (range_type)->high.u.dwarf_loclist.type
3988 +        = die_type (target_die, target_cu);
3989 +      TYPE_DYNAMIC (range_type) = 1;
3990      }
3991    else
3992      {
3993 -      attr = dwarf2_attr (die, DW_AT_count, cu);
3994 -      if (attr)
3995 +      LONGEST high;
3996 +
3997 +      if (attr && attr_form_is_constant (attr))
3998 +       high = dwarf2_get_attr_constant_value (attr, 0);
3999 +      else
4000         {
4001 -         int count = dwarf2_get_attr_constant_value (attr, 1);
4002 -         high = low + count - 1;
4003 +         TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
4004 +         high = low - 1;
4005         }
4006 +      if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
4007 +       high |= negative_mask;
4008 +      TYPE_HIGH_BOUND (range_type) = high;
4009      }
4010  
4011    /* Dwarf-2 specifications explicitly allows to create subrange types
4012 @@ -6419,20 +7592,41 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
4013         }
4014      }
4015  
4016 -  negative_mask =
4017 -    (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
4018 -  if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
4019 -    low |= negative_mask;
4020 -  if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
4021 -    high |= negative_mask;
4022 +  /* DW_AT_bit_stride is currently unsupported as we count in bytes.  */
4023 +  attr = dwarf2_attr (die, DW_AT_byte_stride, cu);
4024 +  if (attr && attr_form_is_block (attr) && cu->language != language_ada)
4025 +    {
4026 +      TYPE_RANGE_DATA (range_type)->byte_stride.kind
4027 +        = RANGE_BOUND_KIND_DWARF_BLOCK;
4028 +      TYPE_RANGE_DATA (range_type)->byte_stride.u.dwarf_block =
4029 +                                       dwarf2_attr_to_locexpr_baton (attr, cu);
4030 +      TYPE_DYNAMIC (range_type) = 1;
4031 +    }
4032 +  else if (attr && is_ref_attr (attr) && cu->language != language_ada)
4033 +    {
4034 +      struct die_info *target_die;
4035 +      struct dwarf2_cu *target_cu = cu;
4036 +      struct attribute *target_loc_attr;
4037  
4038 -  range_type = create_range_type (NULL, base_type, low, high);
4039 +      target_die = follow_die_ref_or_sig (die, attr, &target_cu);
4040 +      gdb_assert (target_cu->objfile == cu->objfile);
4041 +      target_loc_attr = dwarf2_attr (target_die, DW_AT_location, target_cu);
4042  
4043 -  /* Mark arrays with dynamic length at least as an array of unspecified
4044 -     length.  GDB could check the boundary but before it gets implemented at
4045 -     least allow accessing the array elements.  */
4046 -  if (attr && attr->form == DW_FORM_block1)
4047 -    TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
4048 +      TYPE_RANGE_DATA (range_type)->byte_stride.kind
4049 +        = RANGE_BOUND_KIND_DWARF_LOCLIST;
4050 +      TYPE_RANGE_DATA (range_type)->byte_stride.u.dwarf_loclist.loclist
4051 +        = dwarf2_attr_to_loclist_baton (target_loc_attr, target_cu);
4052 +      TYPE_RANGE_DATA (range_type)->byte_stride.u.dwarf_loclist.type
4053 +        = die_type (target_die, target_cu);
4054 +      TYPE_DYNAMIC (range_type) = 1;
4055 +    }
4056 +  else if (attr && attr_form_is_constant (attr))
4057 +    {
4058 +      TYPE_BYTE_STRIDE (range_type) = dwarf2_get_attr_constant_value (attr, 0);
4059 +      if (TYPE_BYTE_STRIDE (range_type) == 0)
4060 +       complaint (&symfile_complaints,
4061 +                  _("Found DW_AT_byte_stride with unsupported value 0"));
4062 +    }
4063  
4064    name = dwarf2_name (die, cu);
4065    if (name)
4066 @@ -8712,10 +9906,12 @@ var_decode_location (struct attribute *attr, struct symbol *sym,
4067       (i.e. when the value of a register or memory location is
4068       referenced, or a thread-local block, etc.).  Then again, it might
4069       not be worthwhile.  I'm assuming that it isn't unless performance
4070 -     or memory numbers show me otherwise.  */
4071 +     or memory numbers show me otherwise.
4072 +     
4073 +     SYMBOL_CLASS may get overriden by dwarf2_symbol_mark_computed.  */
4074  
4075 -  dwarf2_symbol_mark_computed (attr, sym, cu);
4076    SYMBOL_CLASS (sym) = LOC_COMPUTED;
4077 +  dwarf2_symbol_mark_computed (attr, sym, cu);
4078  }
4079  
4080  /* Given a pointer to a DWARF information entry, figure out if we need
4081 @@ -8746,6 +9942,8 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
4082                                              sizeof (struct symbol));
4083        OBJSTAT (objfile, n_syms++);
4084        memset (sym, 0, sizeof (struct symbol));
4085 +      /* Some methods are called w/o checking SYMBOL_COMPUTED_OPS validity.  */
4086 +      SYMBOL_COMPUTED_OPS (sym) = &dwarf2_missing_funcs;
4087  
4088        /* Cache this symbol's name and the name's demangled form (if any).  */
4089        SYMBOL_LANGUAGE (sym) = cu->language;
4090 @@ -9375,6 +10573,9 @@ read_type_die (struct die_info *die, struct dwarf2_cu *cu)
4091        break;
4092      }
4093  
4094 +  if (this_type)
4095 +    finalize_type (this_type);
4096 +
4097    return this_type;
4098  }
4099  
4100 @@ -11979,67 +13180,102 @@ attr_form_is_constant (struct attribute *attr)
4101      }
4102  }
4103  
4104 -static void
4105 -dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
4106 -                            struct dwarf2_cu *cu)
4107 +/* Convert DW_BLOCK into struct dwarf2_locexpr_baton.  ATTR must be a DW_BLOCK
4108 +   attribute type.  */
4109 +
4110 +static struct dwarf2_locexpr_baton *
4111 +dwarf2_attr_to_locexpr_baton (struct attribute *attr, struct dwarf2_cu *cu)
4112  {
4113 -  if (attr_form_is_section_offset (attr)
4114 -      /* ".debug_loc" may not exist at all, or the offset may be outside
4115 -        the section.  If so, fall through to the complaint in the
4116 -        other branch.  */
4117 -      && DW_UNSND (attr) < dwarf2_per_objfile->loc.size)
4118 -    {
4119 -      struct dwarf2_loclist_baton *baton;
4120 +  struct dwarf2_locexpr_baton *baton;
4121  
4122 -      baton = obstack_alloc (&cu->objfile->objfile_obstack,
4123 -                            sizeof (struct dwarf2_loclist_baton));
4124 -      baton->per_cu = cu->per_cu;
4125 -      gdb_assert (baton->per_cu);
4126 +  gdb_assert (attr_form_is_block (attr));
4127  
4128 -      dwarf2_read_section (dwarf2_per_objfile->objfile,
4129 -                          &dwarf2_per_objfile->loc);
4130 +  baton = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (*baton));
4131 +  baton->per_cu = cu->per_cu;
4132 +  gdb_assert (baton->per_cu);
4133  
4134 -      /* We don't know how long the location list is, but make sure we
4135 -        don't run off the edge of the section.  */
4136 -      baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr);
4137 -      baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr);
4138 -      baton->base_address = cu->base_address;
4139 -      if (cu->base_known == 0)
4140 -       complaint (&symfile_complaints,
4141 -                  _("Location list used without specifying the CU base address."));
4142 +  /* Note that we're just copying the block's data pointer
4143 +     here, not the actual data.  We're still pointing into the
4144 +     info_buffer for SYM's objfile; right now we never release
4145 +     that buffer, but when we do clean up properly this may
4146 +     need to change.  */
4147 +  baton->size = DW_BLOCK (attr)->size;
4148 +  baton->data = DW_BLOCK (attr)->data;
4149 +  gdb_assert (baton->size == 0 || baton->data != NULL);
4150 +
4151 +  return baton;
4152 +}
4153 +
4154 +static struct dwarf2_loclist_baton *
4155 +dwarf2_attr_to_loclist_baton (struct attribute *attr, struct dwarf2_cu *cu)
4156 +{
4157 +  struct dwarf2_loclist_baton *baton;
4158 +
4159 +  /* DW_AT_location of the referenced DIE may be missing if the referenced
4160 +     variable has been optimized out.  */
4161 +  if (!attr)
4162 +    return NULL;
4163 +
4164 +  dwarf2_read_section (dwarf2_per_objfile->objfile,
4165 +                      &dwarf2_per_objfile->loc);
4166 +
4167 +  if (!(attr_form_is_section_offset (attr)
4168 +       /* ".debug_loc" may not exist at all, or the offset may be outside
4169 +          the section.  If so, fall through to the complaint in the
4170 +          other branch.  */
4171 +       && DW_UNSND (attr) < dwarf2_per_objfile->loc.size))
4172 +    return NULL;
4173 +
4174 +  baton = obstack_alloc (&cu->objfile->objfile_obstack,
4175 +                        sizeof (struct dwarf2_loclist_baton));
4176 +  baton->per_cu = cu->per_cu;
4177 +  gdb_assert (baton->per_cu);
4178 +
4179 +  /* We don't know how long the location list is, but make sure we
4180 +     don't run off the edge of the section.  */
4181 +  baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr);
4182 +  baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr);
4183 +  baton->base_address = cu->base_address;
4184 +  if (cu->base_known == 0)
4185 +    complaint (&symfile_complaints,
4186 +              _("Location list used without specifying the CU base address."));
4187 +
4188 +  return baton;
4189 +}
4190 +
4191 +/* SYM may get its SYMBOL_CLASS overriden on invalid ATTR content.  */
4192 +
4193 +static void
4194 +dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
4195 +                            struct dwarf2_cu *cu)
4196 +{
4197 +  struct dwarf2_loclist_baton *loclist_baton;
4198  
4199 +  loclist_baton = dwarf2_attr_to_loclist_baton (attr, cu);
4200 +  if (loclist_baton)
4201 +    {
4202        SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs;
4203 -      SYMBOL_LOCATION_BATON (sym) = baton;
4204 +      SYMBOL_LOCATION_BATON (sym) = loclist_baton;
4205 +    }
4206 +  else if (attr_form_is_block (attr))
4207 +    {
4208 +      SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
4209 +      SYMBOL_LOCATION_BATON (sym) = dwarf2_attr_to_locexpr_baton (attr, cu);
4210      }
4211    else
4212      {
4213 -      struct dwarf2_locexpr_baton *baton;
4214 +      dwarf2_invalid_attrib_class_complaint ("location description",
4215 +                                            SYMBOL_NATURAL_NAME (sym));
4216  
4217 -      baton = obstack_alloc (&cu->objfile->objfile_obstack,
4218 -                            sizeof (struct dwarf2_locexpr_baton));
4219 -      baton->per_cu = cu->per_cu;
4220 -      gdb_assert (baton->per_cu);
4221 +      /* Some methods are called w/o checking SYMBOL_COMPUTED_OPS validity.  */
4222  
4223 -      if (attr_form_is_block (attr))
4224 -       {
4225 -         /* Note that we're just copying the block's data pointer
4226 -            here, not the actual data.  We're still pointing into the
4227 -            info_buffer for SYM's objfile; right now we never release
4228 -            that buffer, but when we do clean up properly this may
4229 -            need to change.  */
4230 -         baton->size = DW_BLOCK (attr)->size;
4231 -         baton->data = DW_BLOCK (attr)->data;
4232 -       }
4233 -      else
4234 -       {
4235 -         dwarf2_invalid_attrib_class_complaint ("location description",
4236 -                                                SYMBOL_NATURAL_NAME (sym));
4237 -         baton->size = 0;
4238 -         baton->data = NULL;
4239 -       }
4240 +      SYMBOL_COMPUTED_OPS (sym) = &dwarf2_missing_funcs;
4241 +      SYMBOL_LOCATION_BATON (sym) = NULL;
4242  
4243 -      SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
4244 -      SYMBOL_LOCATION_BATON (sym) = baton;
4245 +      /* For functions a missing DW_AT_frame_base does not optimize out the
4246 +        whole function definition, only its frame base resolving.  */
4247 +      if (attr->name == DW_AT_location)
4248 +       SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
4249      }
4250  }
4251  
4252 @@ -12050,7 +13286,7 @@ dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
4253  struct objfile *
4254  dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
4255  {
4256 -  struct objfile *objfile = per_cu->psymtab->objfile;
4257 +  struct objfile *objfile = per_cu->objfile;
4258  
4259    /* Return the master objfile, so that we can report and look up the
4260       correct file containing this variable.  */
4261 @@ -12070,7 +13306,7 @@ dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
4262    else
4263      {
4264        /* If the CU is not currently read in, we re-read its header.  */
4265 -      struct objfile *objfile = per_cu->psymtab->objfile;
4266 +      struct objfile *objfile = per_cu->objfile;
4267        struct dwarf2_per_objfile *per_objfile
4268         = objfile_data (objfile, dwarf2_objfile_data_key);
4269        gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
4270 @@ -12092,7 +13328,7 @@ dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu)
4271    else
4272      {
4273        /* If the CU is not currently read in, we re-read its header.  */
4274 -      struct objfile *objfile = per_cu->psymtab->objfile;
4275 +      struct objfile *objfile = per_cu->objfile;
4276        struct dwarf2_per_objfile *per_objfile
4277         = objfile_data (objfile, dwarf2_objfile_data_key);
4278        gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
4279 @@ -12112,7 +13348,7 @@ dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu)
4280  CORE_ADDR
4281  dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu)
4282  {
4283 -  struct objfile *objfile = per_cu->psymtab->objfile;
4284 +  struct objfile *objfile = per_cu->objfile;
4285  
4286    return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4287  }
4288 @@ -12334,6 +13570,30 @@ dwarf2_free_objfile (struct objfile *objfile)
4289    /* Cached DIE trees use xmalloc and the comp_unit_obstack.  */
4290    free_cached_comp_units (NULL);
4291  
4292 +  if (dwarf2_per_objfile->using_index)
4293 +    {
4294 +      int i;
4295 +
4296 +      for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
4297 +       {
4298 +         int j;
4299 +         struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
4300 +
4301 +         if (!cu->v.quick->lines)
4302 +           continue;
4303 +
4304 +         for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
4305 +           {
4306 +             if (cu->v.quick->file_names)
4307 +               xfree ((void *) cu->v.quick->file_names[j]);
4308 +             if (cu->v.quick->full_names)
4309 +               xfree ((void *) cu->v.quick->full_names[j]);
4310 +           }
4311 +
4312 +         free_line_header (cu->v.quick->lines);
4313 +       }
4314 +    }
4315 +
4316    /* Everything else should be on the objfile obstack.  */
4317  }
4318  
4319 @@ -12368,6 +13628,31 @@ offset_and_type_eq (const void *item_lhs, const void *item_rhs)
4320    return ofs_lhs->offset == ofs_rhs->offset;
4321  }
4322  
4323 +/* Fill in generic attributes applicable for type DIEs.  */
4324 +
4325 +static void
4326 +fetch_die_type_attrs (struct die_info *die, struct type *type,
4327 +                     struct dwarf2_cu *cu)
4328 +{
4329 +  struct attribute *attr;
4330 +
4331 +  attr = dwarf2_attr (die, DW_AT_data_location, cu);
4332 +  if (attr_form_is_block (attr))
4333 +    TYPE_DATA_LOCATION_DWARF_BLOCK (type) = dwarf2_attr_to_locexpr_baton (attr,
4334 +                                                                         cu);
4335 +  gdb_assert (!TYPE_DATA_LOCATION_IS_ADDR (type));
4336 +
4337 +  attr = dwarf2_attr (die, DW_AT_allocated, cu);
4338 +  if (attr_form_is_block (attr))
4339 +    TYPE_ALLOCATED (type) = dwarf2_attr_to_locexpr_baton (attr, cu);
4340 +  gdb_assert (!TYPE_NOT_ALLOCATED (type));
4341 +
4342 +  attr = dwarf2_attr (die, DW_AT_associated, cu);
4343 +  if (attr_form_is_block (attr))
4344 +    TYPE_ASSOCIATED (type) = dwarf2_attr_to_locexpr_baton (attr, cu);
4345 +  gdb_assert (!TYPE_NOT_ASSOCIATED (type));
4346 +}
4347 +
4348  /* Set the type associated with DIE to TYPE.  Save it in CU's hash
4349     table if necessary.  For convenience, return TYPE.
4350  
4351 @@ -12391,6 +13676,8 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
4352  {
4353    struct dwarf2_offset_and_type **slot, ofs;
4354  
4355 +  fetch_die_type_attrs (die, type, cu);
4356 +
4357    /* For Ada types, make sure that the gnat-specific data is always
4358       initialized (if not already set).  There are a few types where
4359       we should not be doing so, because the type-specific area is
4360 @@ -12591,8 +13878,567 @@ dwarf2_per_objfile_free (struct objfile *objfile, void *d)
4361    munmap_section_buffer (&data->types);
4362    munmap_section_buffer (&data->frame);
4363    munmap_section_buffer (&data->eh_frame);
4364 +  munmap_section_buffer (&data->gdb_index);
4365 +}
4366 +
4367 +\f
4368 +
4369 +/* The contents of the hash table we create when building the string
4370 +   table.  */
4371 +struct strtab_entry
4372 +{
4373 +  offset_type offset;
4374 +  const char *str;
4375 +};
4376 +
4377 +/* Hash function for a strtab_entry.  */
4378 +static hashval_t
4379 +hash_strtab_entry (const void *e)
4380 +{
4381 +  const struct strtab_entry *entry = e;
4382 +  return mapped_index_string_hash (entry->str);
4383 +}
4384 +
4385 +/* Equality function for a strtab_entry.  */
4386 +static int
4387 +eq_strtab_entry (const void *a, const void *b)
4388 +{
4389 +  const struct strtab_entry *ea = a;
4390 +  const struct strtab_entry *eb = b;
4391 +  return !strcmp (ea->str, eb->str);
4392 +}
4393 +
4394 +/* Create a strtab_entry hash table.  */
4395 +static htab_t
4396 +create_strtab (void)
4397 +{
4398 +  return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry,
4399 +                           xfree, xcalloc, xfree);
4400 +}
4401 +
4402 +/* Add a string to the constant pool.  Return the string's offset in
4403 +   host order.  */
4404 +static offset_type
4405 +add_string (htab_t table, struct obstack *cpool, const char *str)
4406 +{
4407 +  void **slot;
4408 +  struct strtab_entry entry;
4409 +  struct strtab_entry *result;
4410 +
4411 +  entry.str = str;
4412 +  slot = htab_find_slot (table, &entry, INSERT);
4413 +  if (*slot)
4414 +    result = *slot;
4415 +  else
4416 +    {
4417 +      result = XNEW (struct strtab_entry);
4418 +      result->offset = obstack_object_size (cpool);
4419 +      result->str = str;
4420 +      obstack_grow_str0 (cpool, str);
4421 +      *slot = result;
4422 +    }
4423 +  return result->offset;
4424 +}
4425 +
4426 +/* An entry in the symbol table.  */
4427 +struct symtab_index_entry
4428 +{
4429 +  /* The name of the symbol.  */
4430 +  const char *name;
4431 +  /* The offset of the name in the constant pool.  */
4432 +  offset_type index_offset;
4433 +  /* A sorted vector of the indices of all the CUs that hold an object
4434 +     of this name.  */
4435 +  VEC (offset_type) *cu_indices;
4436 +};
4437 +
4438 +/* The symbol table.  This is a power-of-2-sized hash table.  */
4439 +struct mapped_symtab
4440 +{
4441 +  offset_type n_elements;
4442 +  offset_type size;
4443 +  struct symtab_index_entry **data;
4444 +};
4445 +
4446 +/* Hash function for a symtab_index_entry.  */
4447 +static hashval_t
4448 +hash_symtab_entry (const void *e)
4449 +{
4450 +  const struct symtab_index_entry *entry = e;
4451 +  return iterative_hash (VEC_address (offset_type, entry->cu_indices),
4452 +                        sizeof (offset_type) * VEC_length (offset_type,
4453 +                                                           entry->cu_indices),
4454 +                        0);
4455 +}
4456 +
4457 +/* Equality function for a symtab_index_entry.  */
4458 +static int
4459 +eq_symtab_entry (const void *a, const void *b)
4460 +{
4461 +  const struct symtab_index_entry *ea = a;
4462 +  const struct symtab_index_entry *eb = b;
4463 +  int len = VEC_length (offset_type, ea->cu_indices);
4464 +  if (len != VEC_length (offset_type, eb->cu_indices))
4465 +    return 0;
4466 +  return !memcmp (VEC_address (offset_type, ea->cu_indices),
4467 +                 VEC_address (offset_type, eb->cu_indices),
4468 +                 sizeof (offset_type) * len);
4469 +}
4470 +
4471 +/* Destroy a symtab_index_entry.  */
4472 +static void
4473 +delete_symtab_entry (void *p)
4474 +{
4475 +  struct symtab_index_entry *entry = p;
4476 +  VEC_free (offset_type, entry->cu_indices);
4477 +  xfree (entry);
4478 +}
4479 +
4480 +/* Create a hash table holding symtab_index_entry objects.  */
4481 +static htab_t
4482 +create_index_table (void)
4483 +{
4484 +  return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry,
4485 +                           delete_symtab_entry, xcalloc, xfree);
4486 +}
4487 +
4488 +/* Create a new mapped symtab object.  */
4489 +static struct mapped_symtab *
4490 +create_mapped_symtab (void)
4491 +{
4492 +  struct mapped_symtab *symtab = XNEW (struct mapped_symtab);
4493 +  symtab->n_elements = 0;
4494 +  symtab->size = 1024;
4495 +  symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
4496 +  return symtab;
4497 +}
4498 +
4499 +/* Destroy a mapped_symtab.  */
4500 +static void
4501 +cleanup_mapped_symtab (void *p)
4502 +{
4503 +  struct mapped_symtab *symtab = p;
4504 +  /* The contents of the array are freed when the other hash table is
4505 +     destroyed.  */
4506 +  xfree (symtab->data);
4507 +  xfree (symtab);
4508 +}
4509 +
4510 +/* Find a slot in SYMTAB for the symbol NAME.  Returns a pointer to
4511 +   the slot.  */
4512 +static struct symtab_index_entry **
4513 +find_slot (struct mapped_symtab *symtab, const char *name)
4514 +{
4515 +  offset_type index, step, hash = mapped_index_string_hash (name);
4516 +
4517 +  index = hash & (symtab->size - 1);
4518 +  step = ((hash * 17) & (symtab->size - 1)) | 1;
4519 +
4520 +  for (;;)
4521 +    {
4522 +      if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name))
4523 +       return &symtab->data[index];
4524 +      index = (index + step) & (symtab->size - 1);
4525 +    }
4526  }
4527  
4528 +/* Expand SYMTAB's hash table.  */
4529 +static void
4530 +hash_expand (struct mapped_symtab *symtab)
4531 +{
4532 +  offset_type old_size = symtab->size;
4533 +  offset_type i;
4534 +  struct symtab_index_entry **old_entries = symtab->data;
4535 +
4536 +  symtab->size *= 2;
4537 +  symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
4538 +
4539 +  for (i = 0; i < old_size; ++i)
4540 +    {
4541 +      if (old_entries[i])
4542 +       {
4543 +         struct symtab_index_entry **slot = find_slot (symtab,
4544 +                                                       old_entries[i]->name);
4545 +         *slot = old_entries[i];
4546 +       }
4547 +    }
4548 +
4549 +  xfree (old_entries);
4550 +}
4551 +
4552 +/* Add an entry to SYMTAB.  NAME is the name of the symbol.  CU_INDEX
4553 +   is the index of the CU in which the symbol appears.  */
4554 +static void
4555 +add_index_entry (struct mapped_symtab *symtab, const char *name,
4556 +                offset_type cu_index)
4557 +{
4558 +  struct symtab_index_entry **slot;
4559 +
4560 +  ++symtab->n_elements;
4561 +  if (4 * symtab->n_elements / 3 >= symtab->size)
4562 +    hash_expand (symtab);
4563 +
4564 +  slot = find_slot (symtab, name);
4565 +  if (!*slot)
4566 +    {
4567 +      *slot = XNEW (struct symtab_index_entry);
4568 +      (*slot)->name = name;
4569 +      (*slot)->cu_indices = NULL;
4570 +    }
4571 +  /* Don't push an index twice.  Due to how we add entries we only
4572 +     have to check the last one.  */ 
4573 +  if (VEC_empty (offset_type, (*slot)->cu_indices)
4574 +      || VEC_length (offset_type, (*slot)->cu_indices) != cu_index)
4575 +    VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index);
4576 +}
4577 +
4578 +/* Add a vector of indices to the constant pool.  */
4579 +static offset_type
4580 +add_indices_to_cpool (htab_t index_table, struct obstack *cpool,
4581 +                     struct symtab_index_entry *entry)
4582 +{
4583 +  void **slot;
4584 +
4585 +  slot = htab_find_slot (index_table, entry, INSERT);
4586 +  if (!*slot)
4587 +    {
4588 +      offset_type len = VEC_length (offset_type, entry->cu_indices);
4589 +      offset_type val = MAYBE_SWAP (len);
4590 +      offset_type iter;
4591 +      int i;
4592 +
4593 +      *slot = entry;
4594 +      entry->index_offset = obstack_object_size (cpool);
4595 +
4596 +      obstack_grow (cpool, &val, sizeof (val));
4597 +      for (i = 0;
4598 +          VEC_iterate (offset_type, entry->cu_indices, i, iter);
4599 +          ++i)
4600 +       {
4601 +         val = MAYBE_SWAP (iter);
4602 +         obstack_grow (cpool, &val, sizeof (val));
4603 +       }
4604 +    }
4605 +  else
4606 +    {
4607 +      struct symtab_index_entry *old_entry = *slot;
4608 +      entry->index_offset = old_entry->index_offset;
4609 +      entry = old_entry;
4610 +    }
4611 +  return entry->index_offset;
4612 +}
4613 +
4614 +/* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
4615 +   constant pool entries going into the obstack CPOOL.  */
4616 +static void
4617 +write_hash_table (struct mapped_symtab *symtab,
4618 +                 struct obstack *output, struct obstack *cpool)
4619 +{
4620 +  offset_type i;
4621 +  htab_t index_table;
4622 +  htab_t str_table;
4623 +
4624 +  index_table = create_index_table ();
4625 +  str_table = create_strtab ();
4626 +  /* We add all the index vectors to the constant pool first, to
4627 +     ensure alignment is ok.  */
4628 +  for (i = 0; i < symtab->size; ++i)
4629 +    {
4630 +      if (symtab->data[i])
4631 +       add_indices_to_cpool (index_table, cpool, symtab->data[i]);
4632 +    }
4633 +
4634 +  /* Now write out the hash table.  */
4635 +  for (i = 0; i < symtab->size; ++i)
4636 +    {
4637 +      offset_type str_off, vec_off;
4638 +
4639 +      if (symtab->data[i])
4640 +       {
4641 +         str_off = add_string (str_table, cpool, symtab->data[i]->name);
4642 +         vec_off = symtab->data[i]->index_offset;
4643 +       }
4644 +      else
4645 +       {
4646 +         /* While 0 is a valid constant pool index, it is not valid
4647 +            to have 0 for both offsets.  */
4648 +         str_off = 0;
4649 +         vec_off = 0;
4650 +       }
4651 +
4652 +      str_off = MAYBE_SWAP (str_off);
4653 +      vec_off = MAYBE_SWAP (vec_off);
4654 +
4655 +      obstack_grow (output, &str_off, sizeof (str_off));
4656 +      obstack_grow (output, &vec_off, sizeof (vec_off));
4657 +    }
4658 +
4659 +  htab_delete (str_table);
4660 +  htab_delete (index_table);
4661 +}
4662 +
4663 +/* Write an address entry to ADDR_OBSTACK.  The addresses are taken
4664 +   from PST; CU_INDEX is the index of the CU in the vector of all
4665 +   CUs.  */
4666 +static void
4667 +add_address_entry (struct objfile *objfile,
4668 +                  struct obstack *addr_obstack, struct partial_symtab *pst,
4669 +                  unsigned int cu_index)
4670 +{
4671 +  offset_type offset;
4672 +  char addr[8];
4673 +  CORE_ADDR baseaddr;
4674 +
4675 +  baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4676 +
4677 +  store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, pst->textlow - baseaddr);
4678 +  obstack_grow (addr_obstack, addr, 8);
4679 +  store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, pst->texthigh - baseaddr);
4680 +  obstack_grow (addr_obstack, addr, 8);
4681 +  offset = MAYBE_SWAP (cu_index);
4682 +  obstack_grow (addr_obstack, &offset, sizeof (offset_type));
4683 +}
4684 +
4685 +/* Add a list of partial symbols to SYMTAB.  */
4686 +static void
4687 +write_psymbols (struct mapped_symtab *symtab,
4688 +               struct partial_symbol **psymp,
4689 +               int count,
4690 +               offset_type cu_index)
4691 +{
4692 +  for (; count-- > 0; ++psymp)
4693 +    {
4694 +      if (SYMBOL_LANGUAGE (*psymp) == language_ada)
4695 +       error (_("Ada is not currently supported by the index"));
4696 +      add_index_entry (symtab, SYMBOL_NATURAL_NAME (*psymp), cu_index);
4697 +    }
4698 +}
4699 +
4700 +/* Write the contents of an ("unfinished") obstack to FILE.  Throw an
4701 +   exception if there is an error.  */
4702 +static void
4703 +write_obstack (FILE *file, struct obstack *obstack)
4704 +{
4705 +  if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack),
4706 +             file)
4707 +      != obstack_object_size (obstack))
4708 +    error (_("couldn't data write to file"));
4709 +}
4710 +
4711 +/* Unlink a file if the argument is not NULL.  */
4712 +static void
4713 +unlink_if_set (void *p)
4714 +{
4715 +  char **filename = p;
4716 +  if (*filename)
4717 +    unlink (*filename);
4718 +}
4719 +
4720 +/* Create an index file for OBJFILE in the directory DIR.  */
4721 +static void
4722 +write_psymtabs_to_index (struct objfile *objfile, const char *dir)
4723 +{
4724 +  struct cleanup *cleanup;
4725 +  char *filename, *cleanup_filename;
4726 +  struct obstack contents, addr_obstack, constant_pool, symtab_obstack, cu_list;
4727 +  int i;
4728 +  FILE *out_file;
4729 +  struct mapped_symtab *symtab;
4730 +  offset_type val, size_of_contents, total_len;
4731 +  struct stat st;
4732 +  char buf[8];
4733 +
4734 +  if (!objfile->psymtabs)
4735 +    return;
4736 +  if (dwarf2_per_objfile->using_index)
4737 +    error (_("Cannot use an index to create the index"));
4738 +
4739 +  if (stat (objfile->name, &st) < 0)
4740 +    perror_with_name (_("Could not stat"));
4741 +
4742 +  filename = concat (dir, SLASH_STRING, lbasename (objfile->name),
4743 +                    INDEX_SUFFIX, (char *) NULL);
4744 +  cleanup = make_cleanup (xfree, filename);
4745 +
4746 +  out_file = fopen (filename, "wb");
4747 +  if (!out_file)
4748 +    error (_("Can't open `%s' for writing"), filename);
4749 +
4750 +  cleanup_filename = filename;
4751 +  make_cleanup (unlink_if_set, &cleanup_filename);
4752 +
4753 +  symtab = create_mapped_symtab ();
4754 +  make_cleanup (cleanup_mapped_symtab, symtab);
4755 +
4756 +  obstack_init (&addr_obstack);
4757 +  make_cleanup_obstack_free (&addr_obstack);
4758 +
4759 +  obstack_init (&cu_list);
4760 +  make_cleanup_obstack_free (&cu_list);
4761 +
4762 +  for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
4763 +    {
4764 +      struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
4765 +      struct partial_symtab *psymtab = cu->v.psymtab;
4766 +      gdb_byte val[8];
4767 +
4768 +      write_psymbols (symtab,
4769 +                     objfile->global_psymbols.list + psymtab->globals_offset,
4770 +                     psymtab->n_global_syms, i);
4771 +      write_psymbols (symtab,
4772 +                     objfile->static_psymbols.list + psymtab->statics_offset,
4773 +                     psymtab->n_static_syms, i);
4774 +
4775 +      add_address_entry (objfile, &addr_obstack, psymtab, i);
4776 +
4777 +      store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, cu->offset);
4778 +      obstack_grow (&cu_list, val, 8);
4779 +      store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, cu->length);
4780 +      obstack_grow (&cu_list, val, 8);
4781 +    }
4782 +
4783 +  obstack_init (&constant_pool);
4784 +  make_cleanup_obstack_free (&constant_pool);
4785 +  obstack_init (&symtab_obstack);
4786 +  make_cleanup_obstack_free (&symtab_obstack);
4787 +  write_hash_table (symtab, &symtab_obstack, &constant_pool);
4788 +
4789 +  obstack_init (&contents);
4790 +  make_cleanup_obstack_free (&contents);
4791 +  size_of_contents = 5 * sizeof (offset_type);
4792 +  total_len = size_of_contents;
4793 +
4794 +  /* The version number.  */
4795 +  val = MAYBE_SWAP (1);
4796 +  obstack_grow (&contents, &val, sizeof (val));
4797 +
4798 +  /* The offset of the CU list from the start of the file.  */
4799 +  val = MAYBE_SWAP (total_len);
4800 +  obstack_grow (&contents, &val, sizeof (val));
4801 +  total_len += obstack_object_size (&cu_list);
4802 +
4803 +  /* The offset of the address table from the start of the file.  */
4804 +  val = MAYBE_SWAP (total_len);
4805 +  obstack_grow (&contents, &val, sizeof (val));
4806 +  total_len += obstack_object_size (&addr_obstack);
4807 +
4808 +  /* The offset of the symbol table from the start of the file.  */
4809 +  val = MAYBE_SWAP (total_len);
4810 +  obstack_grow (&contents, &val, sizeof (val));
4811 +  total_len += obstack_object_size (&symtab_obstack);
4812 +
4813 +  /* The offset of the constant pool from the start of the file.  */
4814 +  val = MAYBE_SWAP (total_len);
4815 +  obstack_grow (&contents, &val, sizeof (val));
4816 +  total_len += obstack_object_size (&constant_pool);
4817 +
4818 +  gdb_assert (obstack_object_size (&contents) == size_of_contents);
4819 +
4820 +  write_obstack (out_file, &contents);
4821 +  write_obstack (out_file, &cu_list);
4822 +  write_obstack (out_file, &addr_obstack);
4823 +  write_obstack (out_file, &symtab_obstack);
4824 +  write_obstack (out_file, &constant_pool);
4825 +
4826 +  fclose (out_file);
4827 +
4828 +  /* We want to keep the file, so we set cleanup_filename to NULL
4829 +     here.  See unlink_if_set.  */
4830 +  cleanup_filename = NULL;
4831 +
4832 +  do_cleanups (cleanup);
4833 +}
4834 +
4835 +/* The mapped index file format is designed to be directly mmap()able
4836 +   on any architecture.  In most cases, a datum is represented using a
4837 +   little-endian 32-bit integer value, called an offset_type.  Big
4838 +   endian machines must byte-swap the values before using them.
4839 +   Exceptions to this rule are noted.  The data is laid out such that
4840 +   alignment is always respected.
4841 +
4842 +   A mapped index consists of several sections.
4843 +
4844 +   1. The file header.  This is a sequence of values, of offset_type
4845 +   unless otherwise noted:
4846 +   [0] The version number.  Currently 1.
4847 +   [1] The offset, from the start of the file, of the CU list.
4848 +   [2] The offset, from the start of the file, of the address section.
4849 +   [3] The offset, from the start of the file, of the symbol table.
4850 +   [4] The offset, from the start of the file, of the constant pool.
4851 +
4852 +   2. The CU list.  This is a sequence of pairs of 64-bit
4853 +   little-endian values.  The first element in each pair is the offset
4854 +   of a CU in the .debug_info section.  The second element in each
4855 +   pair is the length of that CU.  References to a CU elsewhere in the
4856 +   map are done using a CU index, which is just the 0-based index into
4857 +   this table.
4858 +
4859 +   3. The address section.  The address section consists of a sequence
4860 +   of address entries.  Each address entry has three elements.
4861 +   [0] The low address.  This is a 64-bit little-endian value.
4862 +   [1] The high address.  This is a 64-bit little-endian value.
4863 +   [2] The CU index.  This is an offset_type value.
4864 +
4865 +   4. The symbol table.  This is a hash table.  The size of the hash
4866 +   table is always a power of 2.  The initial hash and the step are
4867 +   currently defined by the `find_slot' function.
4868 +
4869 +   Each slot in the hash table consists of a pair of offset_type
4870 +   values.  The first value is the offset of the symbol's name in the
4871 +   constant pool.  The second value is the offset of the CU vector in
4872 +   the constant pool.
4873 +
4874 +   If both values are 0, then this slot in the hash table is empty.
4875 +   This is ok because while 0 is a valid constant pool index, it
4876 +   cannot be a valid index for both a string and a CU vector.
4877 +
4878 +   A string in the constant pool is stored as a \0-terminated string,
4879 +   as you'd expect.
4880 +
4881 +   A CU vector in the constant pool is a sequence of offset_type
4882 +   values.  The first value is the number of CU indices in the vector.
4883 +   Each subsequent value is the index of a CU in the CU list.  This
4884 +   element in the hash table is used to indicate which CUs define the
4885 +   symbol.
4886 +
4887 +   5. The constant pool.  This is simply a bunch of bytes.  It is
4888 +   organized so that alignment is correct: CU vectors are stored
4889 +   first, followed by strings.  */
4890 +static void
4891 +save_gdb_index_command (char *arg, int from_tty)
4892 +{
4893 +  struct objfile *objfile;
4894 +
4895 +  if (!arg || !*arg)
4896 +    error (_("usage: save gdb-index DIRECTORY"));
4897 +
4898 +  ALL_OBJFILES (objfile)
4899 +  {
4900 +    struct stat st;
4901 +
4902 +    /* If the objfile does not correspond to an actual file, skip it.  */
4903 +    if (stat (objfile->name, &st) < 0)
4904 +      continue;
4905 +
4906 +    dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
4907 +    if (dwarf2_per_objfile)
4908 +      {
4909 +       volatile struct gdb_exception except;
4910 +
4911 +       TRY_CATCH (except, RETURN_MASK_ERROR)
4912 +         {
4913 +           write_psymtabs_to_index (objfile, arg);
4914 +         }
4915 +       if (except.reason < 0)
4916 +         exception_fprintf (gdb_stderr, except,
4917 +                            _("Error while writing index for `%s': "),
4918 +                            objfile->name);
4919 +      }
4920 +  }
4921 +}
4922 +
4923 +\f
4924 +
4925  int dwarf2_always_disassemble;
4926  
4927  static void
4928 @@ -12609,6 +14455,8 @@ void _initialize_dwarf2_read (void);
4929  void
4930  _initialize_dwarf2_read (void)
4931  {
4932 +  struct cmd_list_element *c;
4933 +
4934    dwarf2_objfile_data_key
4935      = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free);
4936  
4937 @@ -12656,4 +14504,9 @@ The value is the maximum depth to print."),
4938                             NULL,
4939                             NULL,
4940                             &setdebuglist, &showdebuglist);
4941 +
4942 +  c = add_cmd ("gdb-index", class_files, save_gdb_index_command,
4943 +              _("Save a .gdb-index file"),
4944 +              &save_cmdlist);
4945 +  set_cmd_completer (c, filename_completer);
4946  }
4947 diff --git a/gdb/elfread.c b/gdb/elfread.c
4948 index 8c00938..a250c58 100644
4949 --- a/gdb/elfread.c
4950 +++ b/gdb/elfread.c
4951 @@ -37,9 +37,13 @@
4952  #include "complaints.h"
4953  #include "demangle.h"
4954  #include "psympriv.h"
4955 +#include "gdbtypes.h"
4956  
4957  extern void _initialize_elfread (void);
4958  
4959 +/* Forward declaration.  */
4960 +static struct sym_fns elf_sym_fns_gdb_index;
4961 +
4962  /* The struct elfinfo is available only during ELF symbol table and
4963     psymtab reading.  It is destroyed at the completion of psymtab-reading.
4964     It's local to elf_symfile_read.  */
4965 @@ -180,7 +184,8 @@ record_minimal_symbol (const char *name, int name_len, int copy_name,
4966  {
4967    struct gdbarch *gdbarch = get_objfile_arch (objfile);
4968  
4969 -  if (ms_type == mst_text || ms_type == mst_file_text)
4970 +  if (ms_type == mst_text || ms_type == mst_file_text
4971 +      || ms_type == mst_text_gnu_ifunc)
4972      address = gdbarch_smash_text_address (gdbarch, address);
4973  
4974    return prim_record_minimal_symbol_full (name, name_len, copy_name, address,
4975 @@ -388,7 +393,10 @@ elf_symtab_read (struct objfile *objfile, int type,
4976             {
4977               if (sym->flags & (BSF_GLOBAL | BSF_WEAK))
4978                 {
4979 -                 ms_type = mst_text;
4980 +                 if (sym->flags & BSF_GNU_INDIRECT_FUNCTION)
4981 +                   ms_type = mst_text_gnu_ifunc;
4982 +                 else
4983 +                   ms_type = mst_text;
4984                 }
4985               else if ((sym->name[0] == '.' && sym->name[1] == 'L')
4986                        || ((sym->flags & BSF_LOCAL)
4987 @@ -569,6 +577,250 @@ elf_symtab_read (struct objfile *objfile, int type,
4988      }
4989  }
4990  
4991 +/* FIXME: Delay it through elf_sym_fns.  */
4992 +
4993 +static void
4994 +elf_rel_plt_read (struct objfile *objfile, asymbol **dyn_symbol_table)
4995 +{
4996 +  bfd *obfd = objfile->obfd;
4997 +  const struct elf_backend_data *bed = get_elf_backend_data (obfd);
4998 +  asection *plt, *relplt, *got_plt;
4999 +  unsigned u;
5000 +  int plt_elf_idx;
5001 +  bfd_size_type reloc_count, reloc;
5002 +  char *string_buffer = NULL;
5003 +  size_t string_buffer_size = 0;
5004 +  struct cleanup *back_to;
5005 +  struct gdbarch *gdbarch = objfile->gdbarch;
5006 +  struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
5007 +  size_t ptr_size = TYPE_LENGTH (ptr_type);
5008 +
5009 +  if (objfile->separate_debug_objfile_backlink)
5010 +    return;
5011 +
5012 +  plt = bfd_get_section_by_name (obfd, ".plt");
5013 +  if (plt == NULL)
5014 +    return;
5015 +  plt_elf_idx = elf_section_data (plt)->this_idx;
5016 +
5017 +  got_plt = bfd_get_section_by_name (obfd, ".got.plt");
5018 +  if (got_plt == NULL)
5019 +    return;
5020 +
5021 +  /* This search algorithm is from _bfd_elf_canonicalize_dynamic_reloc.  */
5022 +  for (relplt = obfd->sections; relplt != NULL; relplt = relplt->next)
5023 +    if (elf_section_data (relplt)->this_hdr.sh_info == plt_elf_idx
5024 +       && (elf_section_data (relplt)->this_hdr.sh_type == SHT_REL
5025 +           || elf_section_data (relplt)->this_hdr.sh_type == SHT_RELA))
5026 +      break;
5027 +  if (relplt == NULL)
5028 +    return;
5029 +
5030 +  if (! bed->s->slurp_reloc_table (obfd, relplt, dyn_symbol_table, TRUE))
5031 +    return;
5032 +
5033 +  back_to = make_cleanup (free_current_contents, &string_buffer);
5034 +
5035 +  reloc_count = relplt->size / elf_section_data (relplt)->this_hdr.sh_entsize;
5036 +  for (reloc = 0; reloc < reloc_count; reloc++)
5037 +    {
5038 +      const char *name, *name_got_plt;
5039 +      struct minimal_symbol *msym;
5040 +      CORE_ADDR address;
5041 +      const char *suffix = "@got.plt";
5042 +      size_t suffix_len = strlen (suffix);
5043 +      size_t name_len;
5044 +
5045 +      name = bfd_asymbol_name (*relplt->relocation[reloc].sym_ptr_ptr);
5046 +      name_len = strlen (name);
5047 +      address = relplt->relocation[reloc].address;
5048 +
5049 +      /* Does the pointer reside in the .got.plt section?  */
5050 +      if (!(bfd_get_section_vma (obfd, got_plt) <= address
5051 +            && address < bfd_get_section_vma (obfd, got_plt)
5052 +                        + bfd_get_section_size (got_plt)))
5053 +       continue;
5054 +
5055 +      /* We cannot check if NAME is a reference to mst_text_gnu_ifunc as in
5056 +        OBJFILE the symbol is undefined and the objfile having NAME defined
5057 +        may not yet have been loaded.  */
5058 +
5059 +      if (string_buffer_size < name_len + suffix_len)
5060 +       {
5061 +         string_buffer_size = 2 * (name_len + suffix_len);
5062 +         string_buffer = xrealloc (string_buffer, string_buffer_size);
5063 +       }
5064 +      memcpy (string_buffer, name, name_len);
5065 +      memcpy (&string_buffer[name_len], suffix, suffix_len);
5066 +
5067 +      msym = record_minimal_symbol (string_buffer, name_len + suffix_len, 1,
5068 +                                   address, mst_slot_got_plt, got_plt,
5069 +                                   objfile);
5070 +      if (msym)
5071 +       MSYMBOL_SIZE (msym) = ptr_size;
5072 +    }
5073 +
5074 +  do_cleanups (back_to);
5075 +}
5076 +
5077 +/* Function does not check for possibly created duplicities in the cache.
5078 +   Check it by resolve_gnu_ifunc_by_cache first.  */
5079 +
5080 +static struct minimal_symbol *
5081 +gnu_ifunc_record_cache_unchecked (const char *function_name,
5082 +                                 CORE_ADDR function_address)
5083 +{
5084 +  struct minimal_symbol *msym, *msym_new;
5085 +  asection *sect;
5086 +  struct objfile *objfile;
5087 +  char *function_name_gnu_ifunc_tgt;
5088 +
5089 +  msym = lookup_minimal_symbol_by_pc (function_address);
5090 +  if (msym == NULL)
5091 +    return NULL;
5092 +  if (SYMBOL_VALUE_ADDRESS (msym) != function_address)
5093 +    return NULL;
5094 +  /* minimal symbols have always SYMBOL_OBJ_SECTION non-NULL.  */
5095 +  sect = SYMBOL_OBJ_SECTION (msym)->the_bfd_section;
5096 +  objfile = SYMBOL_OBJ_SECTION (msym)->objfile;
5097 +
5098 +  /* If .plt jumps back to .plt the symbol is still deferred for later
5099 +     resolution and it has no use for GDB.  Besides ".text" this symbol can
5100 +     reside also in ".opd" for ppc64 function descriptor.  */
5101 +  if (strcmp (bfd_get_section_name (objfile->obfd, sect), ".plt") == 0)
5102 +    return NULL;
5103 +
5104 +  function_name_gnu_ifunc_tgt = alloca (strlen (function_name)
5105 +                                       + strlen ("@gnu-ifunc-tgt") + 1);
5106 +  sprintf (function_name_gnu_ifunc_tgt, "%s@gnu-ifunc-tgt", function_name);
5107 +
5108 +  /* Create new alias "@gnu-ifunc-tgt" for MSYM.  */
5109 +  msym_new = record_minimal_symbol (function_name_gnu_ifunc_tgt,
5110 +                                   strlen (function_name_gnu_ifunc_tgt), 1,
5111 +                                   SYMBOL_VALUE_ADDRESS (msym),
5112 +                                   MSYMBOL_TYPE (msym), sect, objfile);
5113 +  /* Should not happen.  */
5114 +  if (msym_new == NULL)
5115 +    return 0;
5116 +
5117 +  /* objfile->msymbols array is already allocated on obstack and it cannot be
5118 +     easily extended.  Therefore <tab>-completion on symbol names will never
5119 +     show the @gnu-ifunc-tgt symbol.  Link it at least to the hash table so
5120 +     that resolve_gnu_ifunc_by_cache can find it.  */
5121 +  add_minsym_to_hash_table (msym_new, objfile->msymbol_hash);
5122 +    
5123 +  MSYMBOL_SIZE (msym_new) = MSYMBOL_SIZE (msym);
5124 +  return msym_new;
5125 +}
5126 +
5127 +/* Check first the cache if it - unlikely - has not been populated since
5128 +   bp_gnu_ifunc_resolver has been created.  gnu_ifunc_record_cache_unchecked
5129 +   could create a duplicate symbol otherwise.  */
5130 +
5131 +void
5132 +gnu_ifunc_record_cache (struct gdbarch *gdbarch, const char *function_name,
5133 +                       CORE_ADDR function_address)
5134 +{
5135 +  struct minimal_symbol *msym;
5136 +
5137 +  msym = resolve_gnu_ifunc_by_cache (function_name);
5138 +  if (msym == NULL)
5139 +    gnu_ifunc_record_cache_unchecked (function_name, function_address);
5140 +  else if (SYMBOL_VALUE_ADDRESS (msym) != function_address)
5141 +    {
5142 +      /* This case indicates buggy inferior program.  GDB would need to update
5143 +        its MSYM cache symbol for function_address.  Anyway FUNCTION_NAME is
5144 +        never normally found in the case as in such case no
5145 +        bp_gnu_ifunc_resolver would be created in the first place.  */
5146 +
5147 +      warning (_("gnu-indirect-function \"%s\" has changed its resolved "
5148 +                "function_address from %s to %s; GDB is using the former one"),
5149 +              function_name, paddress (gdbarch, SYMBOL_VALUE_ADDRESS (msym)),
5150 +              paddress (gdbarch, function_address));
5151 +    }
5152 +}
5153 +
5154 +static struct minimal_symbol *
5155 +resolve_gnu_ifunc_by_got (const char *function_name)
5156 +{
5157 +  char *function_name_got_plt;
5158 +  struct objfile *objfile;
5159 +
5160 +  function_name_got_plt = alloca (strlen (function_name) + strlen ("@got.plt")
5161 +                                 + 1);
5162 +  sprintf (function_name_got_plt, "%s@got.plt", function_name);
5163 +
5164 +  ALL_PSPACE_OBJFILES (current_program_space, objfile)
5165 +    {
5166 +      bfd *obfd = objfile->obfd;
5167 +      struct gdbarch *gdbarch = objfile->gdbarch;
5168 +      struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
5169 +      size_t ptr_size = TYPE_LENGTH (ptr_type);
5170 +      CORE_ADDR pointer_address, function_address;
5171 +      asection *plt;
5172 +      gdb_byte *buf = alloca (ptr_size);
5173 +      struct minimal_symbol *msym;
5174 +
5175 +      msym = lookup_minimal_symbol (function_name_got_plt, NULL, objfile);
5176 +      if (msym == NULL)
5177 +       continue;
5178 +      if (MSYMBOL_TYPE (msym) != mst_slot_got_plt)
5179 +       continue;
5180 +      pointer_address = SYMBOL_VALUE_ADDRESS (msym);
5181 +
5182 +      plt = bfd_get_section_by_name (obfd, ".plt");
5183 +      if (plt == NULL)
5184 +       continue;
5185 +
5186 +      if (MSYMBOL_SIZE (msym) != ptr_size)
5187 +       continue;
5188 +      if (target_read_memory (pointer_address, buf, ptr_size) != 0)
5189 +       continue;
5190 +      function_address = extract_typed_address (buf, ptr_type);
5191 +
5192 +      msym = gnu_ifunc_record_cache_unchecked (function_name, function_address);
5193 +      if (msym == NULL)
5194 +       continue;
5195 +      return msym;
5196 +    }
5197 +
5198 +  return NULL;
5199 +}
5200 +
5201 +struct minimal_symbol *
5202 +resolve_gnu_ifunc_by_cache (const char *function_name)
5203 +{
5204 +  char *function_name_gnu_ifunc_tgt;
5205 +
5206 +  function_name_gnu_ifunc_tgt = alloca (strlen (function_name)
5207 +                                       + strlen ("@gnu-ifunc-tgt") + 1);
5208 +  sprintf (function_name_gnu_ifunc_tgt, "%s@gnu-ifunc-tgt", function_name);
5209 +
5210 +  return lookup_minimal_symbol (function_name_gnu_ifunc_tgt, NULL, NULL);
5211 +}
5212 +
5213 +int
5214 +resolve_gnu_ifunc (const char *function_name, CORE_ADDR *function_addressp)
5215 +{
5216 +  struct minimal_symbol *msym;
5217 +
5218 +  msym = resolve_gnu_ifunc_by_cache (function_name);
5219 +  if (msym != NULL)
5220 +    {
5221 +      *function_addressp = SYMBOL_VALUE_ADDRESS (msym);
5222 +      return 1;
5223 +    }
5224 +
5225 +  msym = resolve_gnu_ifunc_by_got (function_name);
5226 +  if (msym != NULL)
5227 +    {
5228 +      *function_addressp = SYMBOL_VALUE_ADDRESS (msym);
5229 +      return 1;
5230 +    }
5231 +
5232 +  return 0;
5233 +}
5234 +
5235  struct build_id
5236    {
5237      size_t size;
5238 @@ -797,6 +1049,8 @@ elf_symfile_read (struct objfile *objfile, int symfile_flags)
5239                bfd_errmsg (bfd_get_error ()));
5240  
5241        elf_symtab_read (objfile, ST_DYNAMIC, dynsymcount, dyn_symbol_table, 0);
5242 +
5243 +      elf_rel_plt_read (objfile, dyn_symbol_table);
5244      }
5245  
5246    /* Add synthetic symbols - for instance, names for any PLT entries.  */
5247 @@ -869,11 +1123,9 @@ elf_symfile_read (struct objfile *objfile, int symfile_flags)
5248                                 str_sect->filepos,
5249                                 bfd_section_size (abfd, str_sect));
5250      }
5251 -  if (dwarf2_has_info (objfile))
5252 -    {
5253 -      /* DWARF 2 sections */
5254 -      dwarf2_build_psymtabs (objfile);
5255 -    }
5256 +
5257 +  if (dwarf2_has_info (objfile) && dwarf2_initialize_objfile (objfile))
5258 +    objfile->sf = &elf_sym_fns_gdb_index;
5259  
5260    /* If the file has its own symbol tables it has no separate debug info.
5261       `.dynsym'/`.symtab' go to MSYMBOLS, `.debug_info' goes to SYMTABS/PSYMTABS.
5262 @@ -1049,6 +1301,24 @@ static struct sym_fns elf_sym_fns =
5263    NULL                         /* next: pointer to next struct sym_fns */
5264  };
5265  
5266 +/* The same as elf_sym_fns, but not registered and uses the
5267 +   DWARF-specific GNU index rather than psymtab.  */
5268 +static struct sym_fns elf_sym_fns_gdb_index =
5269 +{
5270 +  bfd_target_elf_flavour,
5271 +  elf_new_init,                        /* sym_new_init: init anything gbl to entire symab */
5272 +  elf_symfile_init,            /* sym_init: read initial info, setup for sym_red() */
5273 +  elf_symfile_read,            /* sym_read: read a symbol file into symtab */
5274 +  elf_symfile_finish,          /* sym_finish: finished with file, cleanup */
5275 +  default_symfile_offsets,     /* sym_offsets:  Translate ext. to int. relocatin */
5276 +  elf_symfile_segments,                /* sym_segments: Get segment information from
5277 +                                  a file.  */
5278 +  NULL,                         /* sym_read_linetable */
5279 +  default_symfile_relocate,    /* sym_relocate: Relocate a debug section.  */
5280 +  &dwarf2_gdb_index_functions,
5281 +  NULL                         /* next: pointer to next struct sym_fns */
5282 +};
5283 +
5284  void
5285  _initialize_elfread (void)
5286  {
5287 diff --git a/gdb/eval.c b/gdb/eval.c
5288 index ff17c34..7b9e871 100644
5289 --- a/gdb/eval.c
5290 +++ b/gdb/eval.c
5291 @@ -44,6 +44,7 @@
5292  #include "objfiles.h"
5293  #include "python/python.h"
5294  #include "wrapper.h"
5295 +#include "dwarf2loc.h"
5296  
5297  #include "gdb_assert.h"
5298  
5299 @@ -788,6 +789,7 @@ evaluate_subexp_standard (struct type *expect_type,
5300    int save_pos1;
5301    struct symbol *function = NULL;
5302    char *function_name = NULL;
5303 +  struct cleanup *old_chain;
5304  
5305    pc = (*pos)++;
5306    op = exp->elts[pc].opcode;
5307 @@ -1772,6 +1774,8 @@ evaluate_subexp_standard (struct type *expect_type,
5308               return value_zero (builtin_type (exp->gdbarch)->builtin_int,
5309                                  not_lval);
5310             }
5311 +         else if (TYPE_GNU_IFUNC (ftype))
5312 +           return allocate_value (TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (ftype)));
5313           else if (TYPE_TARGET_TYPE (ftype))
5314             return allocate_value (TYPE_TARGET_TYPE (ftype));
5315           else
5316 @@ -1798,6 +1802,8 @@ evaluate_subexp_standard (struct type *expect_type,
5317  
5318        /* First determine the type code we are dealing with.  */
5319        arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
5320 +      old_chain = make_cleanup (null_cleanup, 0);
5321 +      object_address_set (value_raw_address (arg1));
5322        type = check_typedef (value_type (arg1));
5323        code = TYPE_CODE (type);
5324  
5325 @@ -1818,6 +1824,7 @@ evaluate_subexp_standard (struct type *expect_type,
5326               code = TYPE_CODE (type);
5327             }
5328         } 
5329 +      do_cleanups (old_chain);
5330  
5331        switch (code)
5332         {
5333 @@ -2254,13 +2261,19 @@ evaluate_subexp_standard (struct type *expect_type,
5334        {
5335         int subscript_array[MAX_FORTRAN_DIMS];
5336         int array_size_array[MAX_FORTRAN_DIMS];
5337 +       int byte_stride_array[MAX_FORTRAN_DIMS];
5338         int ndimensions = 1, i;
5339         struct type *tmp_type;
5340         int offset_item;        /* The array offset where the item lives */
5341 +       CORE_ADDR offset_byte;  /* byte_stride based offset  */
5342 +       unsigned element_size;
5343  
5344         if (nargs > MAX_FORTRAN_DIMS)
5345           error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS);
5346  
5347 +       old_chain = make_cleanup (null_cleanup, 0);
5348 +       object_address_set (value_raw_address (arg1));
5349 +
5350         tmp_type = check_typedef (value_type (arg1));
5351         ndimensions = calc_f77_array_dims (type);
5352  
5353 @@ -2290,6 +2303,9 @@ evaluate_subexp_standard (struct type *expect_type,
5354             upper = f77_get_upperbound (tmp_type);
5355             lower = f77_get_lowerbound (tmp_type);
5356  
5357 +           byte_stride_array[nargs - i - 1] =
5358 +                                       TYPE_ARRAY_BYTE_STRIDE_VALUE (tmp_type);
5359 +
5360             array_size_array[nargs - i - 1] = upper - lower + 1;
5361  
5362             /* Zero-normalize subscripts so that offsetting will work. */
5363 @@ -2308,13 +2324,25 @@ evaluate_subexp_standard (struct type *expect_type,
5364               tmp_type = check_typedef (TYPE_TARGET_TYPE (tmp_type));
5365           }
5366  
5367 +       /* Kept for the f77_get_upperbound / f77_get_lowerbound calls above.  */
5368 +       do_cleanups (old_chain);
5369 +
5370         /* Now let us calculate the offset for this item */
5371  
5372 -       offset_item = subscript_array[ndimensions - 1];
5373 +       offset_item = 0;
5374 +       offset_byte = 0;
5375 +
5376 +       for (i = ndimensions - 1; i >= 0; --i)
5377 +         {
5378 +           offset_item *= array_size_array[i];
5379 +           if (byte_stride_array[i] == 0)
5380 +             offset_item += subscript_array[i];
5381 +           else
5382 +             offset_byte += subscript_array[i] * byte_stride_array[i];
5383 +         }
5384  
5385 -       for (i = ndimensions - 1; i > 0; --i)
5386 -         offset_item =
5387 -           array_size_array[i - 1] * offset_item + subscript_array[i - 1];
5388 +       element_size = TYPE_LENGTH (TYPE_TARGET_TYPE (tmp_type));
5389 +       offset_byte += offset_item * element_size;
5390  
5391         /* Let us now play a dirty trick: we will take arg1 
5392            which is a value node pointing to the topmost level
5393 @@ -2324,7 +2352,7 @@ evaluate_subexp_standard (struct type *expect_type,
5394            returns the correct type value */
5395  
5396         deprecated_set_value_type (arg1, tmp_type);
5397 -       return value_subscripted_rvalue (arg1, offset_item, 0);
5398 +       return value_subscripted_rvalue (arg1, offset_byte);
5399        }
5400  
5401      case BINOP_LOGICAL_AND:
5402 @@ -2558,14 +2586,22 @@ evaluate_subexp_standard (struct type *expect_type,
5403        if (expect_type && TYPE_CODE (expect_type) == TYPE_CODE_PTR)
5404         expect_type = TYPE_TARGET_TYPE (check_typedef (expect_type));
5405        arg1 = evaluate_subexp (expect_type, exp, pos, noside);
5406 +      old_chain = make_cleanup (null_cleanup, 0);
5407 +      object_address_set (value_raw_address (arg1));
5408        type = check_typedef (value_type (arg1));
5409        if (TYPE_CODE (type) == TYPE_CODE_METHODPTR
5410           || TYPE_CODE (type) == TYPE_CODE_MEMBERPTR)
5411         error (_("Attempt to dereference pointer to member without an object"));
5412        if (noside == EVAL_SKIP)
5413 -       goto nosideret;
5414 +       {
5415 +         do_cleanups (old_chain);
5416 +         goto nosideret;
5417 +       }
5418        if (unop_user_defined_p (op, arg1))
5419 -       return value_x_unop (arg1, op, noside);
5420 +       {
5421 +         do_cleanups (old_chain);
5422 +         return value_x_unop (arg1, op, noside);
5423 +       }
5424        else if (noside == EVAL_AVOID_SIDE_EFFECTS)
5425         {
5426           type = check_typedef (value_type (arg1));
5427 @@ -2574,12 +2610,18 @@ evaluate_subexp_standard (struct type *expect_type,
5428           /* In C you can dereference an array to get the 1st elt.  */
5429               || TYPE_CODE (type) == TYPE_CODE_ARRAY
5430             )
5431 -           return value_zero (TYPE_TARGET_TYPE (type),
5432 -                              lval_memory);
5433 +           {
5434 +             do_cleanups (old_chain);
5435 +             return value_zero (TYPE_TARGET_TYPE (type),
5436 +                                lval_memory);
5437 +           }
5438           else if (TYPE_CODE (type) == TYPE_CODE_INT)
5439 -           /* GDB allows dereferencing an int.  */
5440 -           return value_zero (builtin_type (exp->gdbarch)->builtin_int,
5441 -                              lval_memory);
5442 +           {
5443 +             do_cleanups (old_chain);
5444 +             /* GDB allows dereferencing an int.  */
5445 +             return value_zero (builtin_type (exp->gdbarch)->builtin_int,
5446 +                                lval_memory);
5447 +           }
5448           else
5449             error (_("Attempt to take contents of a non-pointer value."));
5450         }
5451 @@ -2589,9 +2631,14 @@ evaluate_subexp_standard (struct type *expect_type,
5452          do.  "long long" variables are rare enough that
5453          BUILTIN_TYPE_LONGEST would seem to be a mistake.  */
5454        if (TYPE_CODE (type) == TYPE_CODE_INT)
5455 -       return value_at_lazy (builtin_type (exp->gdbarch)->builtin_int,
5456 -                             (CORE_ADDR) value_as_address (arg1));
5457 -      return value_ind (arg1);
5458 +       {
5459 +         do_cleanups (old_chain);
5460 +         return value_at_lazy (builtin_type (exp->gdbarch)->builtin_int,
5461 +                               (CORE_ADDR) value_as_address (arg1));
5462 +       }
5463 +      arg1 = value_ind (arg1);
5464 +      do_cleanups (old_chain);
5465 +      return arg1;
5466  
5467      case UNOP_ADDR:
5468        /* C++: check for and handle pointer to members.  */
5469 @@ -2933,7 +2980,7 @@ evaluate_subexp_with_coercion (struct expression *exp,
5470  {
5471    enum exp_opcode op;
5472    int pc;
5473 -  struct value *val;
5474 +  struct value *val = NULL;
5475    struct symbol *var;
5476    struct type *type;
5477  
5478 @@ -2944,12 +2991,17 @@ evaluate_subexp_with_coercion (struct expression *exp,
5479      {
5480      case OP_VAR_VALUE:
5481        var = exp->elts[pc + 2].symbol;
5482 +      /* address_of_variable will call object_address_set for check_typedef.
5483 +        Call it only if required as it can error-out on VAR in register.  */
5484 +      if (TYPE_DYNAMIC (SYMBOL_TYPE (var)))
5485 +       val = address_of_variable (var, exp->elts[pc + 1].block);
5486        type = check_typedef (SYMBOL_TYPE (var));
5487        if (TYPE_CODE (type) == TYPE_CODE_ARRAY
5488           && CAST_IS_CONVERSION (exp->language_defn))
5489         {
5490           (*pos) += 4;
5491 -         val = address_of_variable (var, exp->elts[pc + 1].block);
5492 +         if (!val)
5493 +           val = address_of_variable (var, exp->elts[pc + 1].block);
5494           return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
5495                              val);
5496         }
5497 @@ -3001,9 +3053,13 @@ evaluate_subexp_for_sizeof (struct expression *exp, int *pos)
5498  
5499      case OP_VAR_VALUE:
5500        (*pos) += 4;
5501 -      type = check_typedef (SYMBOL_TYPE (exp->elts[pc + 2].symbol));
5502 -      return
5503 -       value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
5504 +      /* We do not need to call read_var_value but the object evaluation may
5505 +        need to have executed object_address_set which needs valid
5506 +        SYMBOL_VALUE_ADDRESS of the symbol.  Still VALUE returned by
5507 +        read_var_value we left as lazy.  */
5508 +      type = value_type (read_var_value (exp->elts[pc + 2].symbol,
5509 +                                       deprecated_safe_get_selected_frame ()));
5510 +      return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
5511  
5512      default:
5513        val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
5514 diff --git a/gdb/f-lang.h b/gdb/f-lang.h
5515 index f5bb82d..29cf5ba 100644
5516 --- a/gdb/f-lang.h
5517 +++ b/gdb/f-lang.h
5518 @@ -28,6 +28,10 @@ extern void f_error (char *);        /* Defined in f-exp.y */
5519  extern void f_print_type (struct type *, const char *, struct ui_file *, int,
5520                           int);
5521  
5522 +extern const char *f_object_address_data_valid_print_to_stream
5523 +  (struct type *type, struct ui_file *stream);
5524 +extern void f_object_address_data_valid_or_error (struct type *type);
5525 +
5526  extern int f_val_print (struct type *, const gdb_byte *, int, CORE_ADDR,
5527                         struct ui_file *, int,
5528                         const struct value *,
5529 diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c
5530 index d35a255..dec81d5 100644
5531 --- a/gdb/f-typeprint.c
5532 +++ b/gdb/f-typeprint.c
5533 @@ -32,7 +32,7 @@
5534  #include "gdbcore.h"
5535  #include "target.h"
5536  #include "f-lang.h"
5537 -
5538 +#include "dwarf2loc.h"
5539  #include "gdb_string.h"
5540  #include <errno.h>
5541  
5542 @@ -49,6 +49,34 @@ void f_type_print_varspec_prefix (struct type *, struct ui_file *,
5543  void f_type_print_base (struct type *, struct ui_file *, int, int);
5544  \f
5545  
5546 +const char *
5547 +f_object_address_data_valid_print_to_stream (struct type *type,
5548 +                                            struct ui_file *stream)
5549 +{
5550 +  const char *msg;
5551 +
5552 +  msg = object_address_data_not_valid (type);
5553 +  if (msg != NULL)
5554 +    {
5555 +      /* Assuming the content printed to STREAM should not be localized.  */
5556 +      fprintf_filtered (stream, "<%s>", msg);
5557 +    }
5558 +
5559 +  return msg;
5560 +}
5561 +
5562 +void
5563 +f_object_address_data_valid_or_error (struct type *type)
5564 +{
5565 +  const char *msg;
5566 +
5567 +  msg = object_address_data_not_valid (type);
5568 +  if (msg != NULL)
5569 +    {
5570 +      error (_("Cannot access it because the %s."), _(msg));
5571 +    }
5572 +}
5573 +
5574  /* LEVEL is the depth to indent lines by.  */
5575  
5576  void
5577 @@ -58,6 +86,9 @@ f_print_type (struct type *type, const char *varstring, struct ui_file *stream,
5578    enum type_code code;
5579    int demangled_args;
5580  
5581 +  if (f_object_address_data_valid_print_to_stream (type, stream) != NULL)
5582 +    return;
5583 +
5584    f_type_print_base (type, stream, show, level);
5585    code = TYPE_CODE (type);
5586    if ((varstring != NULL && *varstring != '\0')
5587 @@ -165,6 +196,9 @@ f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
5588  
5589    QUIT;
5590  
5591 +  if (TYPE_CODE (type) != TYPE_CODE_TYPEDEF)
5592 +    CHECK_TYPEDEF (type);
5593 +
5594    switch (TYPE_CODE (type))
5595      {
5596      case TYPE_CODE_ARRAY:
5597 diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
5598 index 85f698d..2f72b97 100644
5599 --- a/gdb/f-valprint.c
5600 +++ b/gdb/f-valprint.c
5601 @@ -54,15 +54,17 @@ int f77_array_offset_tbl[MAX_FORTRAN_DIMS + 1][2];
5602  /* The following macro gives us the size of the nth dimension, Where 
5603     n is 1 based. */
5604  
5605 -#define F77_DIM_SIZE(n) (f77_array_offset_tbl[n][1])
5606 +#define F77_DIM_COUNT(n) (f77_array_offset_tbl[n][1])
5607  
5608 -/* The following gives us the offset for row n where n is 1-based. */
5609 +/* The following gives us the element size for row n where n is 1-based. */
5610  
5611 -#define F77_DIM_OFFSET(n) (f77_array_offset_tbl[n][0])
5612 +#define F77_DIM_BYTE_STRIDE(n) (f77_array_offset_tbl[n][0])
5613  
5614  int
5615  f77_get_lowerbound (struct type *type)
5616  {
5617 +  f_object_address_data_valid_or_error (type);
5618 +
5619    if (TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type))
5620      error (_("Lower bound may not be '*' in F77"));
5621  
5622 @@ -72,14 +74,17 @@ f77_get_lowerbound (struct type *type)
5623  int
5624  f77_get_upperbound (struct type *type)
5625  {
5626 +  f_object_address_data_valid_or_error (type);
5627 +
5628    if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
5629      {
5630 -      /* We have an assumed size array on our hands.  Assume that
5631 -        upper_bound == lower_bound so that we show at least 1 element.
5632 -        If the user wants to see more elements, let him manually ask for 'em
5633 -        and we'll subscript the array and show him.  */
5634 +      /* We have an assumed size array on our hands.  As type_length_get
5635 +        already assumes a length zero of arrays with underfined bounds VALADDR
5636 +        passed to the Fortran functions does not contained the real inferior
5637 +        memory content.  User should request printing of specific array
5638 +        elements instead.  */
5639  
5640 -      return f77_get_lowerbound (type);
5641 +      return f77_get_lowerbound (type) - 1;
5642      }
5643  
5644    return TYPE_ARRAY_UPPER_BOUND_VALUE (type);
5645 @@ -134,24 +139,29 @@ f77_create_arrayprint_offset_tbl (struct type *type, struct ui_file *stream)
5646        upper = f77_get_upperbound (tmp_type);
5647        lower = f77_get_lowerbound (tmp_type);
5648  
5649 -      F77_DIM_SIZE (ndimen) = upper - lower + 1;
5650 +      F77_DIM_COUNT (ndimen) = upper - lower + 1;
5651 +
5652 +      F77_DIM_BYTE_STRIDE (ndimen) =
5653 +        TYPE_ARRAY_BYTE_STRIDE_VALUE (tmp_type);
5654  
5655        tmp_type = TYPE_TARGET_TYPE (tmp_type);
5656        ndimen++;
5657      }
5658  
5659 -  /* Now we multiply eltlen by all the offsets, so that later we 
5660 +  /* Now we multiply eltlen by all the BYTE_STRIDEs, so that later we
5661       can print out array elements correctly.  Up till now we 
5662 -     know an offset to apply to get the item but we also 
5663 +     know an eltlen to apply to get the item but we also
5664       have to know how much to add to get to the next item */
5665  
5666    ndimen--;
5667    eltlen = TYPE_LENGTH (tmp_type);
5668 -  F77_DIM_OFFSET (ndimen) = eltlen;
5669 +  if (F77_DIM_BYTE_STRIDE (ndimen) == 0)
5670 +    F77_DIM_BYTE_STRIDE (ndimen) = eltlen;
5671    while (--ndimen > 0)
5672      {
5673 -      eltlen *= F77_DIM_SIZE (ndimen + 1);
5674 -      F77_DIM_OFFSET (ndimen) = eltlen;
5675 +      eltlen *= F77_DIM_COUNT (ndimen + 1);
5676 +      if (F77_DIM_BYTE_STRIDE (ndimen) == 0)
5677 +       F77_DIM_BYTE_STRIDE (ndimen) = eltlen;
5678      }
5679  }
5680  
5681 @@ -172,34 +182,34 @@ f77_print_array_1 (int nss, int ndimensions, struct type *type,
5682  
5683    if (nss != ndimensions)
5684      {
5685 -      for (i = 0; (i < F77_DIM_SIZE (nss) && (*elts) < options->print_max); i++)
5686 +      for (i = 0; (i < F77_DIM_COUNT (nss) && (*elts) < options->print_max); i++)
5687         {
5688           fprintf_filtered (stream, "( ");
5689           f77_print_array_1 (nss + 1, ndimensions, TYPE_TARGET_TYPE (type),
5690 -                            valaddr + i * F77_DIM_OFFSET (nss),
5691 -                            address + i * F77_DIM_OFFSET (nss),
5692 +                            valaddr + i * F77_DIM_BYTE_STRIDE (nss),
5693 +                            address + i * F77_DIM_BYTE_STRIDE (nss),
5694                              stream, recurse, val, options, elts);
5695           fprintf_filtered (stream, ") ");
5696         }
5697 -      if (*elts >= options->print_max && i < F77_DIM_SIZE (nss)) 
5698 +      if (*elts >= options->print_max && i < F77_DIM_COUNT (nss))
5699         fprintf_filtered (stream, "...");
5700      }
5701    else
5702      {
5703 -      for (i = 0; i < F77_DIM_SIZE (nss) && (*elts) < options->print_max;
5704 +      for (i = 0; i < F77_DIM_COUNT (nss) && (*elts) < options->print_max;
5705            i++, (*elts)++)
5706         {
5707           val_print (TYPE_TARGET_TYPE (type),
5708 -                    valaddr + i * F77_DIM_OFFSET (ndimensions),
5709 +                    valaddr + i * F77_DIM_BYTE_STRIDE (ndimensions),
5710                      0,
5711 -                    address + i * F77_DIM_OFFSET (ndimensions),
5712 +                    address + i * F77_DIM_BYTE_STRIDE (ndimensions),
5713                      stream, recurse, val, options, current_language);
5714  
5715 -         if (i != (F77_DIM_SIZE (nss) - 1))
5716 +         if (i != (F77_DIM_COUNT (nss) - 1))
5717             fprintf_filtered (stream, ", ");
5718  
5719           if ((*elts == options->print_max - 1)
5720 -             && (i != (F77_DIM_SIZE (nss) - 1)))
5721 +             && (i != (F77_DIM_COUNT (nss) - 1)))
5722             fprintf_filtered (stream, "...");
5723         }
5724      }
5725 @@ -256,6 +266,9 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
5726    CORE_ADDR addr;
5727    int index;
5728  
5729 +  if (f_object_address_data_valid_print_to_stream (type, stream) != NULL)
5730 +    return 0;
5731 +
5732    CHECK_TYPEDEF (type);
5733    switch (TYPE_CODE (type))
5734      {
5735 diff --git a/gdb/findcmd.c b/gdb/findcmd.c
5736 index ac63a9e..e9ba45c 100644
5737 --- a/gdb/findcmd.c
5738 +++ b/gdb/findcmd.c
5739 @@ -45,6 +45,41 @@ put_bits (bfd_uint64_t data, char *buf, int bits, bfd_boolean big_p)
5740      }
5741  }
5742  
5743 +/* Allocates a buffer in *PATTERN_BUF, with a hard-coded initial size which
5744 +   will be returned in *PATTERN_BUF_SIZE. *PATTERN_BUF_END points to the same
5745 +   place as *PATTERN_BUF, indicating that the buffer is initially empty.  */
5746 +
5747 +void
5748 +allocate_pattern_buffer (char **pattern_buf, char **pattern_buf_end,
5749 +                        ULONGEST *pattern_buf_size)
5750 +{
5751 +#define INITIAL_PATTERN_BUF_SIZE 100
5752 +  *pattern_buf_size = INITIAL_PATTERN_BUF_SIZE;
5753 +  *pattern_buf = xmalloc (*pattern_buf_size);
5754 +  *pattern_buf_end = *pattern_buf;
5755 +}
5756 +
5757 +/* Grows *PATTERN_BUF by a factor of two if it's not large enough to hold
5758 +   VAL_BYTES more bytes  or a 64-bit value, whichever is larger.
5759 +   *PATTERN_BUF_END is updated as necessary.  */
5760 +
5761 +void
5762 +increase_pattern_buffer (char **pattern_buf, char **pattern_buf_end,
5763 +                        ULONGEST *pattern_buf_size, int val_bytes)
5764 +{
5765 +    /* Keep it simple and assume size == 'g' when watching for when we
5766 +       need to grow the pattern buf.  */
5767 +    if ((*pattern_buf_end - *pattern_buf + max (val_bytes, sizeof (int64_t)))
5768 +       > *pattern_buf_size)
5769 +      {
5770 +       size_t current_offset = *pattern_buf_end - *pattern_buf;
5771 +
5772 +       *pattern_buf_size *= 2;
5773 +       *pattern_buf = xrealloc (*pattern_buf, *pattern_buf_size);
5774 +       *pattern_buf_end = *pattern_buf + current_offset;
5775 +      }
5776 +}
5777 +
5778  /* Subroutine of find_command to simplify it.
5779     Parse the arguments of the "find" command.  */
5780  
5781 @@ -61,8 +96,7 @@ parse_find_args (char *args, ULONGEST *max_countp,
5782    char *pattern_buf;
5783    /* Current size of search pattern buffer.
5784       We realloc space as needed.  */
5785 -#define INITIAL_PATTERN_BUF_SIZE 100
5786 -  ULONGEST pattern_buf_size = INITIAL_PATTERN_BUF_SIZE;
5787 +  ULONGEST pattern_buf_size;
5788    /* Pointer to one past the last in-use part of pattern_buf.  */
5789    char *pattern_buf_end;
5790    ULONGEST pattern_len;
5791 @@ -75,8 +109,7 @@ parse_find_args (char *args, ULONGEST *max_countp,
5792    if (args == NULL)
5793      error (_("Missing search parameters."));
5794  
5795 -  pattern_buf = xmalloc (pattern_buf_size);
5796 -  pattern_buf_end = pattern_buf;
5797 +  allocate_pattern_buffer (&pattern_buf, &pattern_buf_end, &pattern_buf_size);
5798    old_cleanups = make_cleanup (free_current_contents, &pattern_buf);
5799  
5800    /* Get search granularity and/or max count if specified.
5801 @@ -175,17 +208,9 @@ parse_find_args (char *args, ULONGEST *max_countp,
5802        v = parse_to_comma_and_eval (&s);
5803        val_bytes = TYPE_LENGTH (value_type (v));
5804  
5805 -      /* Keep it simple and assume size == 'g' when watching for when we
5806 -        need to grow the pattern buf.  */
5807 -      if ((pattern_buf_end - pattern_buf + max (val_bytes, sizeof (int64_t)))
5808 -         > pattern_buf_size)
5809 -       {
5810 -         size_t current_offset = pattern_buf_end - pattern_buf;
5811 +      increase_pattern_buffer (&pattern_buf, &pattern_buf_end,
5812 +                              &pattern_buf_size, val_bytes);
5813  
5814 -         pattern_buf_size *= 2;
5815 -         pattern_buf = xrealloc (pattern_buf, pattern_buf_size);
5816 -         pattern_buf_end = pattern_buf + current_offset;
5817 -       }
5818  
5819        if (size != '\0')
5820         {
5821 @@ -240,6 +265,45 @@ parse_find_args (char *args, ULONGEST *max_countp,
5822    discard_cleanups (old_cleanups);
5823  }
5824  
5825 +/* Drives target_search_memory to sweep through the specified search space,
5826 +   possibly in several iterations (with one call to this function for each
5827 +   iteration).  *START_ADDR is the address where the search starts, and is
5828 +   updated to the next starting address to continue the search.
5829 +   *SEARCH_SPACE_LEN is the amount of bytes which will be searched, and is
5830 +   updated for the next iteration. PATTERN_BUF holds the pattern to be searched
5831 +   for, PATTERN_LEN is the size of the pattern in bytes.  If a match is found,
5832 +   it's address is put in *FOUND_ADDR.
5833 +
5834 +   Returns 1 if found, 0 if not found, and -1 if there was an error requiring
5835 +   halting of the search (e.g. memory read error).  */
5836 +
5837 +int
5838 +search_memory (CORE_ADDR *start_addr, ULONGEST *search_space_len,
5839 +              const char *pattern_buf, ULONGEST pattern_len,
5840 +              CORE_ADDR *found_addr)
5841 +{
5842 +  /* Offset from start of this iteration to the next iteration.  */
5843 +  ULONGEST next_iter_incr;
5844 +  int found;
5845 +    
5846 +  found = target_search_memory (*start_addr, *search_space_len,
5847 +                               pattern_buf, pattern_len, found_addr);
5848 +  if (found <= 0)
5849 +    return found;
5850 +
5851 +  /* Begin next iteration at one byte past this match.  */
5852 +  next_iter_incr = (*found_addr - *start_addr) + 1;
5853 +
5854 +  /* For robustness, we don't let search_space_len go -ve here.  */
5855 +  if (*search_space_len >= next_iter_incr)
5856 +    *search_space_len -= next_iter_incr;
5857 +  else
5858 +    *search_space_len = 0;
5859 +  *start_addr += next_iter_incr;
5860 +
5861 +  return found;
5862 +}
5863 +
5864  static void
5865  find_command (char *args, int from_tty)
5866  {
5867 @@ -270,12 +334,11 @@ find_command (char *args, int from_tty)
5868    while (search_space_len >= pattern_len
5869          && found_count < max_count)
5870      {
5871 -      /* Offset from start of this iteration to the next iteration.  */
5872 -      ULONGEST next_iter_incr;
5873        CORE_ADDR found_addr;
5874 -      int found = target_search_memory (start_addr, search_space_len,
5875 -                                       pattern_buf, pattern_len, &found_addr);
5876 +      int found;
5877  
5878 +      found = search_memory (&start_addr, &search_space_len, pattern_buf,
5879 +                            pattern_len, &found_addr);
5880        if (found <= 0)
5881         break;
5882  
5883 @@ -283,16 +346,6 @@ find_command (char *args, int from_tty)
5884        printf_filtered ("\n");
5885        ++found_count;
5886        last_found_addr = found_addr;
5887 -
5888 -      /* Begin next iteration at one byte past this match.  */
5889 -      next_iter_incr = (found_addr - start_addr) + 1;
5890 -
5891 -      /* For robustness, we don't let search_space_len go -ve here.  */
5892 -      if (search_space_len >= next_iter_incr)
5893 -       search_space_len -= next_iter_incr;
5894 -      else
5895 -       search_space_len = 0;
5896 -      start_addr += next_iter_incr;
5897      }
5898  
5899    /* Record and print the results.  */
5900 diff --git a/gdb/findvar.c b/gdb/findvar.c
5901 index e0ca12c..de6311a 100644
5902 --- a/gdb/findvar.c
5903 +++ b/gdb/findvar.c
5904 @@ -35,6 +35,7 @@
5905  #include "user-regs.h"
5906  #include "block.h"
5907  #include "objfiles.h"
5908 +#include "dwarf2loc.h"
5909  
5910  /* Basic byte-swapping routines.  All 'extract' functions return a
5911     host-format integer from a target-format integer at ADDR which is
5912 @@ -401,27 +402,16 @@ symbol_read_needs_frame (struct symbol *sym)
5913  /* Given a struct symbol for a variable,
5914     and a stack frame id, read the value of the variable
5915     and return a (pointer to a) struct value containing the value. 
5916 -   If the variable cannot be found, return a zero pointer.  */
5917 +   If the variable cannot be found, return a zero pointer.
5918 +   We have to first find the address of the variable before allocating struct
5919 +   value to return as its size may depend on DW_OP_PUSH_OBJECT_ADDRESS possibly
5920 +   used by its type.  */
5921  
5922  struct value *
5923  read_var_value (struct symbol *var, struct frame_info *frame)
5924  {
5925 -  struct value *v;
5926    struct type *type = SYMBOL_TYPE (var);
5927    CORE_ADDR addr;
5928 -  int len;
5929 -
5930 -  if (SYMBOL_CLASS (var) == LOC_COMPUTED
5931 -      || SYMBOL_CLASS (var) == LOC_REGISTER)
5932 -    /* These cases do not use V.  */
5933 -    v = NULL;
5934 -  else
5935 -    {
5936 -      v = allocate_value (type);
5937 -      VALUE_LVAL (v) = lval_memory;    /* The most likely possibility.  */
5938 -    }
5939 -
5940 -  len = TYPE_LENGTH (type);
5941  
5942    if (symbol_read_needs_frame (var))
5943      gdb_assert (frame);
5944 @@ -429,33 +419,43 @@ read_var_value (struct symbol *var, struct frame_info *frame)
5945    switch (SYMBOL_CLASS (var))
5946      {
5947      case LOC_CONST:
5948 -      /* Put the constant back in target format.  */
5949 -      store_signed_integer (value_contents_raw (v), len,
5950 -                           gdbarch_byte_order (get_type_arch (type)),
5951 -                           (LONGEST) SYMBOL_VALUE (var));
5952 -      VALUE_LVAL (v) = not_lval;
5953 -      return v;
5954 +      {
5955 +       /* Put the constant back in target format.  */
5956 +       struct value *v = allocate_value (type);
5957 +       VALUE_LVAL (v) = not_lval;
5958 +       store_signed_integer (value_contents_raw (v), TYPE_LENGTH (type),
5959 +                             gdbarch_byte_order (get_type_arch (type)),
5960 +                             (LONGEST) SYMBOL_VALUE (var));
5961 +       return v;
5962 +      }
5963  
5964      case LOC_LABEL:
5965 -      /* Put the constant back in target format.  */
5966 -      if (overlay_debugging)
5967 -       {
5968 -         CORE_ADDR addr
5969 -           = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var),
5970 -                                       SYMBOL_OBJ_SECTION (var));
5971 +      {
5972 +       /* Put the constant back in target format.  */
5973 +       struct value *v = allocate_value (type);
5974 +       VALUE_LVAL (v) = not_lval;
5975 +       if (overlay_debugging)
5976 +         {
5977 +           CORE_ADDR addr
5978 +             = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var),
5979 +                                         SYMBOL_OBJ_SECTION (var));
5980  
5981 -         store_typed_address (value_contents_raw (v), type, addr);
5982 -       }
5983 -      else
5984 -       store_typed_address (value_contents_raw (v), type,
5985 -                             SYMBOL_VALUE_ADDRESS (var));
5986 -      VALUE_LVAL (v) = not_lval;
5987 -      return v;
5988 +           store_typed_address (value_contents_raw (v), type, addr);
5989 +         }
5990 +       else
5991 +         store_typed_address (value_contents_raw (v), type,
5992 +                               SYMBOL_VALUE_ADDRESS (var));
5993 +       return v;
5994 +      }
5995  
5996      case LOC_CONST_BYTES:
5997 -      memcpy (value_contents_raw (v), SYMBOL_VALUE_BYTES (var), len);
5998 -      VALUE_LVAL (v) = not_lval;
5999 -      return v;
6000 +      {
6001 +       struct value *v = allocate_value (type);
6002 +       VALUE_LVAL (v) = not_lval;
6003 +       memcpy (value_contents_raw (v), SYMBOL_VALUE_BYTES (var),
6004 +               TYPE_LENGTH (type));
6005 +       return v;
6006 +      }
6007  
6008      case LOC_STATIC:
6009        if (overlay_debugging)
6010 @@ -496,12 +496,23 @@ read_var_value (struct symbol *var, struct frame_info *frame)
6011        break;
6012  
6013      case LOC_BLOCK:
6014 -      if (overlay_debugging)
6015 -       set_value_address (v, symbol_overlayed_address
6016 -         (BLOCK_START (SYMBOL_BLOCK_VALUE (var)), SYMBOL_OBJ_SECTION (var)));
6017 -      else
6018 -       set_value_address (v, BLOCK_START (SYMBOL_BLOCK_VALUE (var)));
6019 -      return v;
6020 +      {
6021 +        CORE_ADDR addr;
6022 +       struct value *v;
6023 +
6024 +       if (overlay_debugging)
6025 +         addr = symbol_overlayed_address
6026 +           (BLOCK_START (SYMBOL_BLOCK_VALUE (var)), SYMBOL_OBJ_SECTION (var));
6027 +       else
6028 +         addr = BLOCK_START (SYMBOL_BLOCK_VALUE (var));
6029 +       /* ADDR is set here for ALLOCATE_VALUE's CHECK_TYPEDEF for
6030 +          DW_OP_push_object_address.  */
6031 +       object_address_set (addr);
6032 +       v = allocate_value (type);
6033 +       VALUE_LVAL (v) = lval_memory;
6034 +       set_value_address (v, addr);
6035 +       return v;
6036 +      }
6037  
6038      case LOC_REGISTER:
6039      case LOC_REGPARM_ADDR:
6040 @@ -520,7 +531,6 @@ read_var_value (struct symbol *var, struct frame_info *frame)
6041               error (_("Value of register variable not available."));
6042  
6043             addr = value_as_address (regval);
6044 -           VALUE_LVAL (v) = lval_memory;
6045           }
6046         else
6047           {
6048 @@ -563,18 +573,33 @@ read_var_value (struct symbol *var, struct frame_info *frame)
6049        break;
6050  
6051      case LOC_OPTIMIZED_OUT:
6052 -      VALUE_LVAL (v) = not_lval;
6053 -      set_value_optimized_out (v, 1);
6054 -      return v;
6055 +      {
6056 +        struct value *v = allocate_value (type);
6057 +
6058 +       VALUE_LVAL (v) = not_lval;
6059 +       set_value_optimized_out (v, 1);
6060 +       return v;
6061 +      }
6062  
6063      default:
6064        error (_("Cannot look up value of a botched symbol."));
6065        break;
6066      }
6067  
6068 -  set_value_address (v, addr);
6069 -  set_value_lazy (v, 1);
6070 -  return v;
6071 +  {
6072 +    struct value *v;
6073 +
6074 +    /* ADDR is set here for ALLOCATE_VALUE's CHECK_TYPEDEF for
6075 +       DW_OP_PUSH_OBJECT_ADDRESS.  */
6076 +    object_address_set (addr);
6077 +    v = allocate_value (type);
6078 +    VALUE_LVAL (v) = lval_memory;
6079 +    set_value_address (v, addr);
6080 +
6081 +    set_value_lazy (v, 1);
6082 +
6083 +    return v;
6084 +  }
6085  }
6086  
6087  /* Install default attributes for register values.  */
6088 @@ -611,10 +636,11 @@ struct value *
6089  value_from_register (struct type *type, int regnum, struct frame_info *frame)
6090  {
6091    struct gdbarch *gdbarch = get_frame_arch (frame);
6092 -  struct type *type1 = check_typedef (type);
6093    struct value *v;
6094  
6095 -  if (gdbarch_convert_register_p (gdbarch, regnum, type1))
6096 +  type = check_typedef (type);
6097 +
6098 +  if (gdbarch_convert_register_p (gdbarch, regnum, type))
6099      {
6100        /* The ISA/ABI need to something weird when obtaining the
6101           specified value from this register.  It might need to
6102 @@ -628,7 +654,7 @@ value_from_register (struct type *type, int regnum, struct frame_info *frame)
6103        VALUE_FRAME_ID (v) = get_frame_id (frame);
6104        VALUE_REGNUM (v) = regnum;
6105        gdbarch_register_to_value (gdbarch,
6106 -                                frame, regnum, type1, value_contents_raw (v));
6107 +                                frame, regnum, type, value_contents_raw (v));
6108      }
6109    else
6110      {
6111 diff --git a/gdb/gdbcmd.h b/gdb/gdbcmd.h
6112 index 78151dd..da11686 100644
6113 --- a/gdb/gdbcmd.h
6114 +++ b/gdb/gdbcmd.h
6115 @@ -124,6 +124,10 @@ extern struct cmd_list_element *setchecklist;
6116  
6117  extern struct cmd_list_element *showchecklist;
6118  
6119 +/* Chain containing all defined "save" subcommands.  */
6120 +
6121 +extern struct cmd_list_element *save_cmdlist;
6122 +
6123  extern void execute_command (char *, int);
6124  extern char *execute_command_to_string (char *p, int from_tty);
6125  
6126 diff --git a/gdb/gdbinit.in b/gdb/gdbinit.in
6127 index ffb7f53..a2e7e94 100644
6128 --- a/gdb/gdbinit.in
6129 +++ b/gdb/gdbinit.in
6130 @@ -1,5 +1,15 @@
6131  echo Setting up the environment for debugging gdb.\n
6132  
6133 +# Set up the Python library and "require" command.
6134 +python
6135 +from os.path import abspath
6136 +gdb.datadir = abspath ('@srcdir@/python/lib')
6137 +gdb.pythonlibdir = gdb.datadir
6138 +gdb.__path__ = [gdb.datadir + '/gdb']
6139 +sys.path.insert(0, gdb.datadir)
6140 +end
6141 +source @srcdir@/python/lib/gdb/__init__.py
6142 +
6143  set complaints 1
6144  
6145  b internal_error
6146 diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h
6147 index cd24eaf..9638368 100644
6148 --- a/gdb/gdbthread.h
6149 +++ b/gdb/gdbthread.h
6150 @@ -66,6 +66,9 @@ struct thread_info
6151    /* Step-resume or longjmp-resume breakpoint.  */
6152    struct breakpoint *step_resume_breakpoint;
6153  
6154 +  /* Exception-resume breakpoint.  */
6155 +  struct breakpoint *exception_resume_breakpoint;
6156 +
6157    /* Range to single step within.
6158  
6159       If this is nonzero, respond to a single-step signal by continuing
6160 @@ -185,6 +188,10 @@ struct thread_info
6161    /* True if this thread has been explicitly requested to stop.  */
6162    int stop_requested;
6163  
6164 +  /* The initiating frame of a nexting operation, used for deciding
6165 +     which exceptions to intercept.  */
6166 +  struct frame_id initiating_frame;
6167 +
6168    /* Private data used by the target vector implementation.  */
6169    struct private_thread_info *private;
6170  
6171 @@ -221,6 +228,9 @@ extern void delete_thread_silent (ptid_t);
6172  /* Delete a step_resume_breakpoint from the thread database. */
6173  extern void delete_step_resume_breakpoint (struct thread_info *);
6174  
6175 +/* Delete an exception_resume_breakpoint from the thread database. */
6176 +extern void delete_exception_resume_breakpoint (struct thread_info *);
6177 +
6178  /* Translate the integer thread id (GDB's homegrown id, not the system's)
6179     into a "pid" (which may be overloaded with extra thread information).  */
6180  extern ptid_t thread_id_to_pid (int);
6181 diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
6182 index 443f6f7..d852a14 100644
6183 --- a/gdb/gdbtypes.c
6184 +++ b/gdb/gdbtypes.c
6185 @@ -39,6 +39,9 @@
6186  #include "cp-abi.h"
6187  #include "gdb_assert.h"
6188  #include "hashtab.h"
6189 +#include "observer.h"
6190 +#include "dwarf2expr.h"
6191 +#include "dwarf2loc.h"
6192  
6193  
6194  /* Floatformat pairs.  */
6195 @@ -123,6 +126,11 @@ static void print_arg_types (struct field *, int, int);
6196  static void dump_fn_fieldlists (struct type *, int);
6197  static void print_cplus_stuff (struct type *, int);
6198  
6199 +/* The hash table holding all discardable `struct type *' references.  */
6200 +static htab_t type_discardable_table;
6201 +
6202 +/* Current type_discardable_check pass used for TYPE_DISCARDABLE_AGE.  */
6203 +static int type_discardable_age_current;
6204  
6205  /* Allocate a new OBJFILE-associated type structure and fill it
6206     with some defaults.  Space for the type structure is allocated
6207 @@ -153,6 +161,39 @@ alloc_type (struct objfile *objfile)
6208    return type;
6209  }
6210  
6211 +/* Declare TYPE as discardable on next garbage collection by free_all_types.
6212 +   You must call type_mark_used during each free_all_types to protect TYPE from
6213 +   being deallocated.  */
6214 +
6215 +static void
6216 +set_type_as_discardable (struct type *type)
6217 +{
6218 +  void **slot;
6219 +
6220 +  gdb_assert (!TYPE_DISCARDABLE (type));
6221 +
6222 +  TYPE_DISCARDABLE (type) = 1;
6223 +  TYPE_DISCARDABLE_AGE (type) = type_discardable_age_current;
6224 +
6225 +  slot = htab_find_slot (type_discardable_table, type, INSERT);
6226 +  gdb_assert (!*slot);
6227 +  *slot = type;
6228 +}
6229 +
6230 +/* Allocate a new type like alloc_type but preserve for it the discardability
6231 +   state of PARENT_TYPE.  */
6232 +
6233 +static struct type *
6234 +alloc_type_as_parent (struct type *parent_type)
6235 +{
6236 +  struct type *new_type = alloc_type_copy (parent_type);
6237 +
6238 +  if (TYPE_DISCARDABLE (parent_type))
6239 +    set_type_as_discardable (new_type);
6240 +
6241 +  return new_type;
6242 +}
6243 +
6244  /* Allocate a new GDBARCH-associated type structure and fill it
6245     with some defaults.  Space for the type structure is allocated
6246     on the heap.  */
6247 @@ -278,7 +319,7 @@ make_pointer_type (struct type *type, struct type **typeptr)
6248  
6249    if (typeptr == 0 || *typeptr == 0)   /* We'll need to allocate one.  */
6250      {
6251 -      ntype = alloc_type_copy (type);
6252 +      ntype = alloc_type_as_parent (type);
6253        if (typeptr)
6254         *typeptr = ntype;
6255      }
6256 @@ -355,7 +396,7 @@ make_reference_type (struct type *type, struct type **typeptr)
6257  
6258    if (typeptr == 0 || *typeptr == 0)   /* We'll need to allocate one.  */
6259      {
6260 -      ntype = alloc_type_copy (type);
6261 +      ntype = alloc_type_as_parent (type);
6262        if (typeptr)
6263         *typeptr = ntype;
6264      }
6265 @@ -726,6 +767,7 @@ create_range_type (struct type *result_type, struct type *index_type,
6266      TYPE_ZALLOC (result_type, sizeof (struct range_bounds));
6267    TYPE_LOW_BOUND (result_type) = low_bound;
6268    TYPE_HIGH_BOUND (result_type) = high_bound;
6269 +  TYPE_BYTE_STRIDE (result_type) = 0;
6270  
6271    if (low_bound >= 0)
6272      TYPE_UNSIGNED (result_type) = 1;
6273 @@ -825,26 +867,45 @@ create_array_type (struct type *result_type,
6274  
6275    TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
6276    TYPE_TARGET_TYPE (result_type) = element_type;
6277 -  if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
6278 -    low_bound = high_bound = 0;
6279 -  CHECK_TYPEDEF (element_type);
6280 -  /* Be careful when setting the array length.  Ada arrays can be
6281 -     empty arrays with the high_bound being smaller than the low_bound.
6282 -     In such cases, the array length should be zero.  */
6283 -  if (high_bound < low_bound)
6284 -    TYPE_LENGTH (result_type) = 0;
6285 -  else
6286 -    TYPE_LENGTH (result_type) =
6287 -      TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
6288    TYPE_NFIELDS (result_type) = 1;
6289    TYPE_FIELDS (result_type) =
6290      (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
6291    TYPE_INDEX_TYPE (result_type) = range_type;
6292    TYPE_VPTR_FIELDNO (result_type) = -1;
6293  
6294 -  /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
6295 +  /* DWARF blocks may depend on runtime information like
6296 +     DW_OP_PUSH_OBJECT_ADDRESS not being available during the
6297 +     CREATE_ARRAY_TYPE time.  */
6298 +  if (TYPE_RANGE_DATA (range_type)->low.kind != RANGE_BOUND_KIND_CONSTANT
6299 +      || TYPE_RANGE_DATA (range_type)->high.kind != RANGE_BOUND_KIND_CONSTANT
6300 +      || TYPE_LOW_BOUND_UNDEFINED (range_type) 
6301 +      || TYPE_HIGH_BOUND_UNDEFINED (range_type) 
6302 +      || get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
6303 +    {
6304 +      low_bound = 0;
6305 +      high_bound = -1;
6306 +    }
6307 +
6308 +  /* Be careful when setting the array length.  Ada arrays can be
6309 +     empty arrays with the high_bound being smaller than the low_bound.
6310 +     In such cases, the array length should be zero.  TYPE_TARGET_STUB needs to
6311 +     be checked as it may have dependencies on DWARF blocks depending on
6312 +     runtime information not available during the CREATE_ARRAY_TYPE time.  */
6313 +  if (high_bound < low_bound || TYPE_TARGET_STUB (element_type))
6314 +    TYPE_LENGTH (result_type) = 0;
6315 +  else
6316 +    {
6317 +      CHECK_TYPEDEF (element_type);
6318 +      TYPE_LENGTH (result_type) =
6319 +       TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
6320 +    }
6321 +
6322    if (TYPE_LENGTH (result_type) == 0)
6323 -    TYPE_TARGET_STUB (result_type) = 1;
6324 +    {
6325 +      /* The real size will be computed for specific instances by
6326 +        CHECK_TYPEDEF.  */
6327 +      TYPE_TARGET_STUB (result_type) = 1;
6328 +    }
6329  
6330    return result_type;
6331  }
6332 @@ -1353,6 +1414,105 @@ stub_noname_complaint (void)
6333    complaint (&symfile_complaints, _("stub type has NULL name"));
6334  }
6335  
6336 +/* Calculate the memory length of array TYPE.
6337 +
6338 +   TARGET_TYPE should be set to `check_typedef (TYPE_TARGET_TYPE (type))' as
6339 +   a performance hint.  Feel free to pass NULL.  Set FULL_SPAN to return the
6340 +   size incl. the possible padding of the last element - it may differ from the
6341 +   cleared FULL_SPAN return value (the expected SIZEOF) for non-zero
6342 +   TYPE_BYTE_STRIDE values.  */
6343 +
6344 +static LONGEST
6345 +type_length_get (struct type *type, struct type *target_type, int full_span)
6346 +{
6347 +  struct type *range_type;
6348 +  LONGEST byte_stride = 0;     /* `= 0' for a false GCC warning.  */
6349 +  LONGEST count, element_size, retval;
6350 +
6351 +  if (TYPE_CODE (type) != TYPE_CODE_ARRAY
6352 +      && TYPE_CODE (type) != TYPE_CODE_STRING)
6353 +    return TYPE_LENGTH (type);
6354 +
6355 +  /* Avoid executing TYPE_HIGH_BOUND for invalid (unallocated/unassociated)
6356 +     Fortran arrays.  The allocated data will never be used so they can be
6357 +     zero-length.  */
6358 +  if (object_address_data_not_valid (type))
6359 +    return 0;
6360 +
6361 +  range_type = TYPE_INDEX_TYPE (type);
6362 +  if (TYPE_LOW_BOUND_UNDEFINED (range_type)
6363 +      || TYPE_HIGH_BOUND_UNDEFINED (range_type))
6364 +    return 0;
6365 +  count = TYPE_HIGH_BOUND (range_type) - TYPE_LOW_BOUND (range_type) + 1;
6366 +  /* It may happen for wrong DWARF annotations returning garbage data.  */
6367 +  if (count < 0)
6368 +    warning (_("Range for type %s has invalid bounds %s..%s"),
6369 +            TYPE_NAME (type), plongest (TYPE_LOW_BOUND (range_type)),
6370 +            plongest (TYPE_HIGH_BOUND (range_type)));
6371 +  /* The code below does not handle count == 0 right.  */
6372 +  if (count <= 0)
6373 +    return 0;
6374 +  if (full_span || count > 1)
6375 +    {
6376 +      /* We do not use TYPE_ARRAY_BYTE_STRIDE_VALUE (type) here as we want to
6377 +         force FULL_SPAN to 1.  */
6378 +      byte_stride = TYPE_BYTE_STRIDE (range_type);
6379 +      if (byte_stride == 0)
6380 +        {
6381 +         if (target_type == NULL)
6382 +           target_type = check_typedef (TYPE_TARGET_TYPE (type));
6383 +         byte_stride = type_length_get (target_type, NULL, 1);
6384 +       }
6385 +    }
6386 +
6387 +  /* For now, we conservatively take the array length to be 0 if its length
6388 +     exceeds UINT_MAX.  The code below assumes that for x < 0,
6389 +     (ULONGEST) x == -x + ULONGEST_MAX + 1, which is technically not guaranteed
6390 +     by C, but is usually true (because it would be true if x were unsigned
6391 +     with its high-order bit on). It uses the fact that high_bound-low_bound is
6392 +     always representable in ULONGEST and that if high_bound-low_bound+1
6393 +     overflows, it overflows to 0.  We must change these tests if we decide to
6394 +     increase the representation of TYPE_LENGTH from unsigned int to ULONGEST.
6395 +     */
6396 +
6397 +  if (full_span)
6398 +    {
6399 +      retval = count * byte_stride;
6400 +      if (count == 0 || retval / count != byte_stride || retval > UINT_MAX)
6401 +       retval = 0;
6402 +      return retval;
6403 +    }
6404 +  if (target_type == NULL)
6405 +    target_type = check_typedef (TYPE_TARGET_TYPE (type));
6406 +  element_size = type_length_get (target_type, NULL, 1);
6407 +  retval = (count - 1) * byte_stride + element_size;
6408 +  if (retval < element_size
6409 +      || (byte_stride != 0
6410 +          && (retval - element_size) / byte_stride != count - 1)
6411 +      || retval > UINT_MAX)
6412 +    retval = 0;
6413 +  return retval;
6414 +}
6415 +
6416 +/* Prepare TYPE after being read in by the backend.  Currently this function
6417 +   only propagates the TYPE_DYNAMIC flag.  */
6418 +
6419 +void
6420 +finalize_type (struct type *type)
6421 +{
6422 +  int i;
6423 +
6424 +  for (i = 0; i < TYPE_NFIELDS (type); ++i)
6425 +    if (TYPE_FIELD_TYPE (type, i) && TYPE_DYNAMIC (TYPE_FIELD_TYPE (type, i)))
6426 +      break;
6427 +
6428 +  /* FIXME: cplus_stuff is ignored here.  */
6429 +  if (i < TYPE_NFIELDS (type)
6430 +      || (TYPE_VPTR_BASETYPE (type) && TYPE_DYNAMIC (TYPE_VPTR_BASETYPE (type)))
6431 +      || (TYPE_TARGET_TYPE (type) && TYPE_DYNAMIC (TYPE_TARGET_TYPE (type))))
6432 +    TYPE_DYNAMIC (type) = 1;
6433 +}
6434 +
6435  /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
6436  
6437     If this is a stubbed struct (i.e. declared as struct foo *), see if
6438 @@ -1486,52 +1646,36 @@ check_typedef (struct type *type)
6439          }
6440      }
6441  
6442 -  if (TYPE_TARGET_STUB (type))
6443 +  /* copy_type_recursive automatically makes the resulting type containing only
6444 +     constant values expected by the callers of this function.  */
6445 +  if (TYPE_DYNAMIC (type))
6446 +    {
6447 +      htab_t copied_types;
6448 +      struct type *type_old = type;
6449 +
6450 +      copied_types = create_copied_types_hash (NULL);
6451 +      type = copy_type_recursive (type, copied_types);
6452 +      htab_delete (copied_types);
6453 +
6454 +      gdb_assert (TYPE_DYNAMIC (type) == 0);
6455 +    }
6456 +
6457 +  if (TYPE_TARGET_STUB (type) || TYPE_DYNAMIC (type))
6458      {
6459 -      struct type *range_type;
6460        struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
6461  
6462 +      if (TYPE_DYNAMIC (type))
6463 +       TYPE_TARGET_TYPE (type) = target_type;
6464        if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
6465         {
6466           /* Empty.  */
6467         }
6468        else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
6469 -              && TYPE_NFIELDS (type) == 1
6470 -              && (TYPE_CODE (range_type = TYPE_INDEX_TYPE (type))
6471 -                  == TYPE_CODE_RANGE))
6472 +              || TYPE_CODE (type) == TYPE_CODE_STRING)
6473         {
6474           /* Now recompute the length of the array type, based on its
6475 -            number of elements and the target type's length.
6476 -            Watch out for Ada null Ada arrays where the high bound
6477 -            is smaller than the low bound. */
6478 -         const LONGEST low_bound = TYPE_LOW_BOUND (range_type);
6479 -         const LONGEST high_bound = TYPE_HIGH_BOUND (range_type);
6480 -         ULONGEST len;
6481 -
6482 -         if (high_bound < low_bound)
6483 -           len = 0;
6484 -         else
6485 -           {
6486 -             /* For now, we conservatively take the array length to be 0
6487 -                if its length exceeds UINT_MAX.  The code below assumes
6488 -                that for x < 0, (ULONGEST) x == -x + ULONGEST_MAX + 1,
6489 -                which is technically not guaranteed by C, but is usually true
6490 -                (because it would be true if x were unsigned with its
6491 -                high-order bit on). It uses the fact that
6492 -                high_bound-low_bound is always representable in
6493 -                ULONGEST and that if high_bound-low_bound+1 overflows,
6494 -                it overflows to 0.  We must change these tests if we 
6495 -                decide to increase the representation of TYPE_LENGTH
6496 -                from unsigned int to ULONGEST. */
6497 -             ULONGEST ulow = low_bound, uhigh = high_bound;
6498 -             ULONGEST tlen = TYPE_LENGTH (target_type);
6499 -
6500 -             len = tlen * (uhigh - ulow + 1);
6501 -             if (tlen == 0 || (len / tlen - 1 + ulow) != uhigh 
6502 -                 || len > UINT_MAX)
6503 -               len = 0;
6504 -           }
6505 -         TYPE_LENGTH (type) = len;
6506 +            number of elements and the target type's length.  */
6507 +         TYPE_LENGTH (type) = type_length_get (type, target_type, 0);
6508           TYPE_TARGET_STUB (type) = 0;
6509         }
6510        else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
6511 @@ -1539,9 +1683,12 @@ check_typedef (struct type *type)
6512           TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
6513           TYPE_TARGET_STUB (type) = 0;
6514         }
6515 +      TYPE_DYNAMIC (type) = 0;
6516      }
6517 +
6518    /* Cache TYPE_LENGTH for future use.  */
6519    TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
6520 +
6521    return type;
6522  }
6523  
6524 @@ -1811,6 +1958,8 @@ init_type (enum type_code code, int length, int flags,
6525      TYPE_NOTTEXT (type) = 1;
6526    if (flags & TYPE_FLAG_FIXED_INSTANCE)
6527      TYPE_FIXED_INSTANCE (type) = 1;
6528 +  if (flags & TYPE_FLAG_GNU_IFUNC)
6529 +    TYPE_GNU_IFUNC (type) = 1;
6530  
6531    if (name)
6532      TYPE_NAME (type) = obsavestring (name, strlen (name),
6533 @@ -3006,33 +3155,42 @@ type_pair_eq (const void *item_lhs, const void *item_rhs)
6534  }
6535  
6536  /* Allocate the hash table used by copy_type_recursive to walk
6537 -   types without duplicates.  We use OBJFILE's obstack, because
6538 -   OBJFILE is about to be deleted.  */
6539 +   types without duplicates.   */
6540  
6541  htab_t
6542  create_copied_types_hash (struct objfile *objfile)
6543  {
6544 -  return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
6545 -                              NULL, &objfile->objfile_obstack,
6546 -                              hashtab_obstack_allocate,
6547 -                              dummy_obstack_deallocate);
6548 +  if (objfile == NULL)
6549 +    {
6550 +      /* NULL OBJFILE is for TYPE_DYNAMIC types already contained in
6551 +        OBJFILE_MALLOC memory, such as those from VALUE_HISTORY_CHAIN.  Table
6552 +        element entries get allocated by xmalloc - so use xfree.  */
6553 +      return htab_create (1, type_pair_hash, type_pair_eq, xfree);
6554 +    }
6555 +  else
6556 +    {
6557 +      /* Use OBJFILE's obstack, because OBJFILE is about to be deleted.  Table
6558 +        element entries get allocated by xmalloc - so use xfree.  */
6559 +      return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
6560 +                                  xfree, &objfile->objfile_obstack,
6561 +                                  hashtab_obstack_allocate,
6562 +                                  dummy_obstack_deallocate);
6563 +    }
6564  }
6565  
6566 -/* Recursively copy (deep copy) TYPE, if it is associated with
6567 -   OBJFILE.  Return a new type allocated using malloc, a saved type if
6568 -   we have already visited TYPE (using COPIED_TYPES), or TYPE if it is
6569 -   not associated with OBJFILE.  */
6570 +/* A helper for copy_type_recursive.  This does all the work.  OBJFILE is used
6571 +   only for an assertion checking.  */
6572  
6573 -struct type *
6574 -copy_type_recursive (struct objfile *objfile, 
6575 -                    struct type *type,
6576 -                    htab_t copied_types)
6577 +static struct type *
6578 +copy_type_recursive_1 (struct objfile *objfile, 
6579 +                      struct type *type,
6580 +                      htab_t copied_types)
6581  {
6582    struct type_pair *stored, pair;
6583    void **slot;
6584    struct type *new_type;
6585  
6586 -  if (! TYPE_OBJFILE_OWNED (type))
6587 +  if (! TYPE_OBJFILE_OWNED (type) && !TYPE_DYNAMIC (type))
6588      return type;
6589  
6590    /* This type shouldn't be pointing to any types in other objfiles;
6591 @@ -3047,8 +3205,10 @@ copy_type_recursive (struct objfile *objfile,
6592    new_type = alloc_type_arch (get_type_arch (type));
6593  
6594    /* We must add the new type to the hash table immediately, in case
6595 -     we encounter this type again during a recursive call below.  */
6596 -  stored = obstack_alloc (&objfile->objfile_obstack, sizeof (struct type_pair));
6597 +     we encounter this type again during a recursive call below.  Memory could
6598 +     be allocated from OBJFILE in the case we will be removing OBJFILE, this
6599 +     optimization is missed and xfree is called for it from COPIED_TYPES.  */
6600 +  stored = xmalloc (sizeof (*stored));
6601    stored->old = type;
6602    stored->new = new_type;
6603    *slot = stored;
6604 @@ -3059,6 +3219,19 @@ copy_type_recursive (struct objfile *objfile,
6605    TYPE_OBJFILE_OWNED (new_type) = 0;
6606    TYPE_OWNER (new_type).gdbarch = get_type_arch (type);
6607  
6608 +  /* TYPE_MAIN_TYPE memory copy above rewrote the TYPE_DISCARDABLE flag so we
6609 +     need to initialize it again.  And even if TYPE was already discardable
6610 +     NEW_TYPE so far is not registered in TYPE_DISCARDABLE_TABLE.  */
6611 +  TYPE_DISCARDABLE (new_type) = 0;
6612 +  set_type_as_discardable (new_type);
6613 +
6614 +  /* Pre-clear the fields processed by delete_main_type.  If DWARF block
6615 +     evaluations below call error we would leave an unfreeable TYPE.  */
6616 +  TYPE_TARGET_TYPE (new_type) = NULL;
6617 +  TYPE_VPTR_BASETYPE (new_type) = NULL;
6618 +  TYPE_NFIELDS (new_type) = 0;
6619 +  TYPE_FIELDS (new_type) = NULL;
6620 +
6621    if (TYPE_NAME (type))
6622      TYPE_NAME (new_type) = xstrdup (TYPE_NAME (type));
6623    if (TYPE_TAG_NAME (type))
6624 @@ -3067,12 +3240,48 @@ copy_type_recursive (struct objfile *objfile,
6625    TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
6626    TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
6627  
6628 +  if (TYPE_ALLOCATED (new_type))
6629 +    {
6630 +      gdb_assert (!TYPE_NOT_ALLOCATED (new_type));
6631 +
6632 +      if (!dwarf_locexpr_baton_eval (TYPE_ALLOCATED (new_type)))
6633 +        TYPE_NOT_ALLOCATED (new_type) = 1;
6634 +      TYPE_ALLOCATED (new_type) = NULL;
6635 +    }
6636 +
6637 +  if (TYPE_ASSOCIATED (new_type))
6638 +    {
6639 +      gdb_assert (!TYPE_NOT_ASSOCIATED (new_type));
6640 +
6641 +      if (!dwarf_locexpr_baton_eval (TYPE_ASSOCIATED (new_type)))
6642 +        TYPE_NOT_ASSOCIATED (new_type) = 1;
6643 +      TYPE_ASSOCIATED (new_type) = NULL;
6644 +    }
6645 +
6646 +  if (!TYPE_DATA_LOCATION_IS_ADDR (new_type)
6647 +      && TYPE_DATA_LOCATION_DWARF_BLOCK (new_type))
6648 +    {
6649 +      if (TYPE_NOT_ALLOCATED (new_type)
6650 +          || TYPE_NOT_ASSOCIATED (new_type))
6651 +       TYPE_DATA_LOCATION_DWARF_BLOCK (new_type) = NULL;
6652 +      else
6653 +       {
6654 +         TYPE_DATA_LOCATION_IS_ADDR (new_type) = 1;
6655 +         TYPE_DATA_LOCATION_ADDR (new_type) = dwarf_locexpr_baton_eval
6656 +                                   (TYPE_DATA_LOCATION_DWARF_BLOCK (new_type));
6657 +       }
6658 +    }
6659 +
6660    /* Copy the fields.  */
6661    if (TYPE_NFIELDS (type))
6662      {
6663        int i, nfields;
6664  
6665 +      /* TYPE_CODE_RANGE uses TYPE_RANGE_DATA of the union with TYPE_FIELDS.  */
6666 +      gdb_assert (TYPE_CODE (type) != TYPE_CODE_RANGE);
6667 +
6668        nfields = TYPE_NFIELDS (type);
6669 +      TYPE_NFIELDS (new_type) = nfields;
6670        TYPE_FIELDS (new_type) = XCALLOC (nfields, struct field);
6671        for (i = 0; i < nfields; i++)
6672         {
6673 @@ -3081,8 +3290,8 @@ copy_type_recursive (struct objfile *objfile,
6674           TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i);
6675           if (TYPE_FIELD_TYPE (type, i))
6676             TYPE_FIELD_TYPE (new_type, i)
6677 -             = copy_type_recursive (objfile, TYPE_FIELD_TYPE (type, i),
6678 -                                    copied_types);
6679 +             = copy_type_recursive_1 (objfile, TYPE_FIELD_TYPE (type, i),
6680 +                                      copied_types);
6681           if (TYPE_FIELD_NAME (type, i))
6682             TYPE_FIELD_NAME (new_type, i) = 
6683               xstrdup (TYPE_FIELD_NAME (type, i));
6684 @@ -3109,24 +3318,166 @@ copy_type_recursive (struct objfile *objfile,
6685         }
6686      }
6687  
6688 +  /* Both FIELD_LOC_KIND_DWARF_BLOCK and TYPE_RANGE_HIGH_BOUND_IS_COUNT were
6689 +     possibly converted.  */
6690 +  TYPE_DYNAMIC (new_type) = 0;
6691 +
6692    /* For range types, copy the bounds information. */
6693 -  if (TYPE_CODE (type) == TYPE_CODE_RANGE)
6694 +  if (TYPE_CODE (new_type) == TYPE_CODE_RANGE)
6695      {
6696        TYPE_RANGE_DATA (new_type) = xmalloc (sizeof (struct range_bounds));
6697        *TYPE_RANGE_DATA (new_type) = *TYPE_RANGE_DATA (type);
6698 +
6699 +      switch (TYPE_RANGE_DATA (new_type)->low.kind)
6700 +       {
6701 +       case RANGE_BOUND_KIND_CONSTANT:
6702 +         break;
6703 +       case RANGE_BOUND_KIND_DWARF_BLOCK:
6704 +         /* `struct dwarf2_locexpr_baton' is too bound to its objfile so
6705 +            it is expected to be made constant by CHECK_TYPEDEF.
6706 +            TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
6707 +            */
6708 +         if (TYPE_NOT_ALLOCATED (new_type) || TYPE_NOT_ASSOCIATED (new_type)
6709 +             || ! has_stack_frames ())
6710 +           {
6711 +             /* We should set 1 for Fortran but how to find the language?  */
6712 +             TYPE_LOW_BOUND (new_type) = 0;
6713 +             TYPE_LOW_BOUND_UNDEFINED (new_type) = 1;
6714 +           }
6715 +         else
6716 +           TYPE_LOW_BOUND (new_type) = dwarf_locexpr_baton_eval
6717 +                               (TYPE_RANGE_DATA (new_type)->low.u.dwarf_block);
6718 +         TYPE_RANGE_DATA (new_type)->low.kind = RANGE_BOUND_KIND_CONSTANT;
6719 +         break;
6720 +       case RANGE_BOUND_KIND_DWARF_LOCLIST:
6721 +         {
6722 +           CORE_ADDR addr;
6723 +
6724 +           /* `struct dwarf2_loclist_baton' is too bound to its objfile so
6725 +              it is expected to be made constant by CHECK_TYPEDEF.
6726 +              TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
6727 +              */
6728 +           if (! TYPE_NOT_ALLOCATED (new_type)
6729 +               && ! TYPE_NOT_ASSOCIATED (new_type) && has_stack_frames ()
6730 +               && dwarf_loclist_baton_eval
6731 +                 (TYPE_RANGE_DATA (new_type)->low.u.dwarf_loclist.loclist,
6732 +                  TYPE_RANGE_DATA (new_type)->low.u.dwarf_loclist.type, &addr))
6733 +             TYPE_LOW_BOUND (new_type) = addr;
6734 +           else
6735 +             {
6736 +               /* We should set 1 for Fortran but how to find the language?  */
6737 +               TYPE_LOW_BOUND (new_type) = 0;
6738 +               TYPE_LOW_BOUND_UNDEFINED (new_type) = 1;
6739 +             }
6740 +           TYPE_RANGE_DATA (new_type)->low.kind = RANGE_BOUND_KIND_CONSTANT;
6741 +         }
6742 +         break;
6743 +       }
6744 +
6745 +      switch (TYPE_RANGE_DATA (new_type)->high.kind)
6746 +       {
6747 +       case RANGE_BOUND_KIND_CONSTANT:
6748 +         break;
6749 +       case RANGE_BOUND_KIND_DWARF_BLOCK:
6750 +         /* `struct dwarf2_locexpr_baton' is too bound to its objfile so
6751 +            it is expected to be made constant by CHECK_TYPEDEF.
6752 +            TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
6753 +            */
6754 +         if (TYPE_NOT_ALLOCATED (new_type) || TYPE_NOT_ASSOCIATED (new_type)
6755 +             || ! has_stack_frames ())
6756 +           {
6757 +             TYPE_HIGH_BOUND (new_type) = TYPE_LOW_BOUND (new_type) - 1;
6758 +             TYPE_HIGH_BOUND_UNDEFINED (new_type) = 1;
6759 +           }
6760 +         else
6761 +           TYPE_HIGH_BOUND (new_type) = dwarf_locexpr_baton_eval
6762 +                              (TYPE_RANGE_DATA (new_type)->high.u.dwarf_block);
6763 +         TYPE_RANGE_DATA (new_type)->high.kind = RANGE_BOUND_KIND_CONSTANT;
6764 +         break;
6765 +       case RANGE_BOUND_KIND_DWARF_LOCLIST:
6766 +         {
6767 +           CORE_ADDR addr;
6768 +
6769 +           /* `struct dwarf2_loclist_baton' is too bound to its objfile so
6770 +              it is expected to be made constant by CHECK_TYPEDEF.
6771 +              TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
6772 +              */
6773 +           if (! TYPE_NOT_ALLOCATED (new_type)
6774 +               && ! TYPE_NOT_ASSOCIATED (new_type) && has_stack_frames ()
6775 +               && dwarf_loclist_baton_eval
6776 +                     (TYPE_RANGE_DATA (new_type)->high.u.dwarf_loclist.loclist,
6777 +                      TYPE_RANGE_DATA (new_type)->high.u.dwarf_loclist.type,
6778 +                      &addr))
6779 +             TYPE_HIGH_BOUND (new_type) = addr;
6780 +           else
6781 +             {
6782 +               TYPE_HIGH_BOUND (new_type) = TYPE_LOW_BOUND (new_type) - 1;
6783 +               TYPE_HIGH_BOUND_UNDEFINED (new_type) = 1;
6784 +             }
6785 +           TYPE_RANGE_DATA (new_type)->high.kind = RANGE_BOUND_KIND_CONSTANT;
6786 +         }
6787 +         break;
6788 +       }
6789 +
6790 +      switch (TYPE_RANGE_DATA (new_type)->byte_stride.kind)
6791 +       {
6792 +       case RANGE_BOUND_KIND_CONSTANT:
6793 +         break;
6794 +       case RANGE_BOUND_KIND_DWARF_BLOCK:
6795 +         /* `struct dwarf2_locexpr_baton' is too bound to its objfile so
6796 +            it is expected to be made constant by CHECK_TYPEDEF.
6797 +            TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
6798 +            */
6799 +         if (TYPE_NOT_ALLOCATED (new_type) || TYPE_NOT_ASSOCIATED (new_type)
6800 +             || ! has_stack_frames ())
6801 +           TYPE_BYTE_STRIDE (new_type) = 0;
6802 +         else
6803 +           TYPE_BYTE_STRIDE (new_type) = dwarf_locexpr_baton_eval
6804 +                       (TYPE_RANGE_DATA (new_type)->byte_stride.u.dwarf_block);
6805 +         TYPE_RANGE_DATA (new_type)->byte_stride.kind
6806 +           = RANGE_BOUND_KIND_CONSTANT;
6807 +         break;
6808 +       case RANGE_BOUND_KIND_DWARF_LOCLIST:
6809 +         {
6810 +           CORE_ADDR addr = 0;
6811 +
6812 +           /* `struct dwarf2_loclist_baton' is too bound to its objfile so
6813 +              it is expected to be made constant by CHECK_TYPEDEF.
6814 +              TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
6815 +              */
6816 +           if (! TYPE_NOT_ALLOCATED (new_type)
6817 +               && ! TYPE_NOT_ASSOCIATED (new_type) && has_stack_frames ())
6818 +             dwarf_loclist_baton_eval
6819 +              (TYPE_RANGE_DATA (new_type)->byte_stride.u.dwarf_loclist.loclist,
6820 +               TYPE_RANGE_DATA (new_type)->byte_stride.u.dwarf_loclist.type,
6821 +               &addr);
6822 +           TYPE_BYTE_STRIDE (new_type) = addr;
6823 +           TYPE_RANGE_DATA (new_type)->byte_stride.kind
6824 +             = RANGE_BOUND_KIND_CONSTANT;
6825 +         }
6826 +         break;
6827 +       }
6828 +
6829 +      /* Convert TYPE_RANGE_HIGH_BOUND_IS_COUNT into a regular bound.  */
6830 +      if (TYPE_RANGE_HIGH_BOUND_IS_COUNT (new_type))
6831 +       {
6832 +         TYPE_HIGH_BOUND (new_type) = TYPE_LOW_BOUND (new_type)
6833 +                                      + TYPE_HIGH_BOUND (new_type) - 1;
6834 +         TYPE_RANGE_HIGH_BOUND_IS_COUNT (new_type) = 0;
6835 +       }
6836      }
6837  
6838    /* Copy pointers to other types.  */
6839    if (TYPE_TARGET_TYPE (type))
6840      TYPE_TARGET_TYPE (new_type) = 
6841 -      copy_type_recursive (objfile, 
6842 -                          TYPE_TARGET_TYPE (type),
6843 -                          copied_types);
6844 +      copy_type_recursive_1 (objfile, 
6845 +                            TYPE_TARGET_TYPE (type),
6846 +                            copied_types);
6847    if (TYPE_VPTR_BASETYPE (type))
6848      TYPE_VPTR_BASETYPE (new_type) = 
6849 -      copy_type_recursive (objfile,
6850 -                          TYPE_VPTR_BASETYPE (type),
6851 -                          copied_types);
6852 +      copy_type_recursive_1 (objfile,
6853 +                            TYPE_VPTR_BASETYPE (type),
6854 +                            copied_types);
6855    /* Maybe copy the type_specific bits.
6856  
6857       NOTE drow/2005-12-09: We do not copy the C++-specific bits like
6858 @@ -3143,6 +3494,17 @@ copy_type_recursive (struct objfile *objfile,
6859    return new_type;
6860  }
6861  
6862 +/* Recursively copy (deep copy) TYPE.  Return a new type allocated using
6863 +   malloc, a saved type if we have already visited TYPE (using COPIED_TYPES),
6864 +   or TYPE if it is not associated with OBJFILE.  */
6865 +
6866 +struct type *
6867 +copy_type_recursive (struct type *type,
6868 +                    htab_t copied_types)
6869 +{
6870 +  return copy_type_recursive_1 (TYPE_OBJFILE (type), type, copied_types);
6871 +}
6872 +
6873  /* Make a copy of the given TYPE, except that the pointer & reference
6874     types are not preserved.
6875     
6876 @@ -3165,6 +3527,199 @@ copy_type (const struct type *type)
6877    return new_type;
6878  }
6879  
6880 +/* Callback type for main_type_crawl.  */
6881 +typedef int (*main_type_crawl_iter) (struct type *type, void *data);
6882 +
6883 +/* Iterate all main_type structures reachable through any `struct type *' from
6884 +   TYPE.  ITER will be called only for one type of each main_type, use
6885 +   TYPE_CHAIN traversal to find all the type instances.  ITER is being called
6886 +   for each main_type found.  ITER returns non-zero if main_type_crawl should
6887 +   depth-first enter the specific type.  ITER must provide some detection for
6888 +   reentering the same main_type as this function would otherwise endlessly
6889 +   loop.  */
6890 +
6891 +static void
6892 +main_type_crawl (struct type *type, main_type_crawl_iter iter, void *data)
6893 +{
6894 +  struct type *type_iter;
6895 +  int i;
6896 +
6897 +  if (!type)
6898 +    return;
6899 +
6900 +  gdb_assert (TYPE_OBJFILE (type) == NULL);
6901 +
6902 +  /* `struct cplus_struct_type' handling is unsupported by this function.  */
6903 +  gdb_assert ((TYPE_CODE (type) != TYPE_CODE_STRUCT
6904 +              && TYPE_CODE (type) != TYPE_CODE_UNION)
6905 +             || !HAVE_CPLUS_STRUCT (type));
6906 +
6907 +  if (!(*iter) (type, data))
6908 +    return;
6909 +
6910 +  /* Iterate all the type instances of this main_type.  */
6911 +  type_iter = type;
6912 +  do
6913 +    {
6914 +      gdb_assert (TYPE_MAIN_TYPE (type_iter) == TYPE_MAIN_TYPE (type));
6915 +
6916 +      main_type_crawl (TYPE_POINTER_TYPE (type), iter, data);
6917 +      main_type_crawl (TYPE_REFERENCE_TYPE (type), iter, data);
6918 +
6919 +      type_iter = TYPE_CHAIN (type_iter);
6920 +    }
6921 +  while (type_iter != type);
6922 +
6923 +  for (i = 0; i < TYPE_NFIELDS (type); i++)
6924 +    main_type_crawl (TYPE_FIELD_TYPE (type, i), iter, data);
6925 +
6926 +  main_type_crawl (TYPE_TARGET_TYPE (type), iter, data);
6927 +  main_type_crawl (TYPE_VPTR_BASETYPE (type), iter, data);
6928 +}
6929 +
6930 +/* A helper for delete_type which deletes a main_type and the things to which
6931 +   it refers.  TYPE is a type whose main_type we wish to destroy.  */
6932 +
6933 +static void
6934 +delete_main_type (struct type *type)
6935 +{
6936 +  int i;
6937 +
6938 +  gdb_assert (TYPE_DISCARDABLE (type));
6939 +  gdb_assert (TYPE_OBJFILE (type) == NULL);
6940 +
6941 +  xfree (TYPE_NAME (type));
6942 +  xfree (TYPE_TAG_NAME (type));
6943 +
6944 +  for (i = 0; i < TYPE_NFIELDS (type); ++i)
6945 +    {
6946 +      xfree (TYPE_FIELD_NAME (type, i));
6947 +
6948 +      if (TYPE_FIELD_LOC_KIND (type, i) == FIELD_LOC_KIND_PHYSNAME)
6949 +       xfree (TYPE_FIELD_STATIC_PHYSNAME (type, i));
6950 +    }
6951 +  xfree (TYPE_FIELDS (type));
6952 +
6953 +  gdb_assert (!HAVE_CPLUS_STRUCT (type));
6954 +
6955 +  xfree (TYPE_MAIN_TYPE (type));
6956 +}
6957 +
6958 +/* Delete all the instances on TYPE_CHAIN of TYPE, including their referenced
6959 +   main_type.  TYPE must be a reclaimable type - neither permanent nor objfile
6960 +   associated.  */
6961 +
6962 +static void
6963 +delete_type_chain (struct type *type)
6964 +{
6965 +  struct type *type_iter, *type_iter_to_free;
6966 +
6967 +  gdb_assert (TYPE_DISCARDABLE (type));
6968 +  gdb_assert (TYPE_OBJFILE (type) == NULL);
6969 +
6970 +  delete_main_type (type);
6971 +
6972 +  type_iter = type;
6973 +  do
6974 +    {
6975 +      type_iter_to_free = type_iter;
6976 +      type_iter = TYPE_CHAIN (type_iter);
6977 +      xfree (type_iter_to_free);
6978 +    }
6979 +  while (type_iter != type);
6980 +}
6981 +
6982 +/* Hash function for type_discardable_table.  */
6983 +
6984 +static hashval_t
6985 +type_discardable_hash (const void *p)
6986 +{
6987 +  const struct type *type = p;
6988 +
6989 +  return htab_hash_pointer (TYPE_MAIN_TYPE (type));
6990 +}
6991 +
6992 +/* Equality function for type_discardable_table.  */
6993 +
6994 +static int
6995 +type_discardable_equal (const void *a, const void *b)
6996 +{
6997 +  const struct type *left = a;
6998 +  const struct type *right = b;
6999 +
7000 +  return TYPE_MAIN_TYPE (left) == TYPE_MAIN_TYPE (right);
7001 +}
7002 +
7003 +/* A helper for type_mark_used.  */
7004 +
7005 +static int
7006 +type_mark_used_crawl (struct type *type, void *unused)
7007 +{
7008 +  if (!TYPE_DISCARDABLE (type))
7009 +    return 0;
7010 +
7011 +  if (TYPE_DISCARDABLE_AGE (type) == type_discardable_age_current)
7012 +    return 0;
7013 +
7014 +  TYPE_DISCARDABLE_AGE (type) = type_discardable_age_current;
7015 +
7016 +  /* Continue the traversal.  */
7017 +  return 1;
7018 +}
7019 +
7020 +/* Mark TYPE and its connected types as used in this free_all_types pass.  */
7021 +
7022 +void
7023 +type_mark_used (struct type *type)
7024 +{
7025 +  if (type == NULL)
7026 +    return;
7027 +
7028 +  if (!TYPE_DISCARDABLE (type))
7029 +    return;
7030 +
7031 +  main_type_crawl (type, type_mark_used_crawl, NULL);
7032 +}
7033 +
7034 +/* A traverse callback for type_discardable_table which removes any
7035 +   type_discardable whose reference count is now zero (unused link).  */
7036 +
7037 +static int
7038 +type_discardable_remove (void **slot, void *unused)
7039 +{
7040 +  struct type *type = *slot;
7041 +
7042 +  gdb_assert (TYPE_DISCARDABLE (type));
7043 +
7044 +  if (TYPE_DISCARDABLE_AGE (type) != type_discardable_age_current)
7045 +    {
7046 +      delete_type_chain (type);
7047 +
7048 +      htab_clear_slot (type_discardable_table, slot);
7049 +    }
7050 +
7051 +  return 1;
7052 +}
7053 +
7054 +/* Free all the reclaimable types that have been allocated and that have
7055 +   currently zero reference counter.
7056 +
7057 +   This function is called after each command, successful or not.  Use this
7058 +   cleanup only in the GDB idle state as GDB only marks those types used by
7059 +   globally tracked objects (with no autovariable references tracking).  */
7060 +
7061 +void
7062 +free_all_types (void)
7063 +{
7064 +  /* Mark a new pass.  As GDB checks all the entries were visited after each
7065 +     pass there cannot be any stale entries already containing the changed
7066 +     value.  */
7067 +  type_discardable_age_current ^= 1;
7068 +
7069 +  observer_notify_mark_used ();
7070 +
7071 +  htab_traverse (type_discardable_table, type_discardable_remove, NULL);
7072 +}
7073  
7074  /* Helper functions to initialize architecture-specific types.  */
7075  
7076 @@ -3511,6 +4066,8 @@ gdbtypes_post_init (struct gdbarch *gdbarch)
7077      = lookup_pointer_type (builtin_type->builtin_void);
7078    builtin_type->builtin_func_ptr
7079      = lookup_pointer_type (lookup_function_type (builtin_type->builtin_void));
7080 +  builtin_type->builtin_func_func
7081 +    = lookup_function_type (builtin_type->builtin_func_ptr);
7082  
7083    /* This type represents a GDB internal function.  */
7084    builtin_type->internal_fn
7085 @@ -3624,6 +4181,18 @@ objfile_type (struct objfile *objfile)
7086                  "<text variable, no debug info>", objfile);
7087    TYPE_TARGET_TYPE (objfile_type->nodebug_text_symbol)
7088      = objfile_type->builtin_int;
7089 +  objfile_type->nodebug_text_gnu_ifunc_symbol
7090 +    = init_type (TYPE_CODE_FUNC, 1, TYPE_FLAG_GNU_IFUNC,
7091 +                "<text gnu-indirect-function variable, no debug info>",
7092 +                objfile);
7093 +  TYPE_TARGET_TYPE (objfile_type->nodebug_text_gnu_ifunc_symbol)
7094 +    = objfile_type->nodebug_text_symbol;
7095 +  objfile_type->nodebug_got_plt_symbol
7096 +    = init_type (TYPE_CODE_PTR, gdbarch_addr_bit (gdbarch) / 8, 0,
7097 +                "<text from jump slot in .got.plt, no debug info>",
7098 +                objfile);
7099 +  TYPE_TARGET_TYPE (objfile_type->nodebug_got_plt_symbol)
7100 +    = objfile_type->nodebug_text_symbol;
7101    objfile_type->nodebug_data_symbol
7102      = init_type (TYPE_CODE_INT,
7103                  gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0,
7104 @@ -3678,6 +4247,11 @@ void
7105  _initialize_gdbtypes (void)
7106  {
7107    gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init);
7108 +
7109 +  type_discardable_table = htab_create_alloc (20, type_discardable_hash,
7110 +                                            type_discardable_equal, NULL,
7111 +                                            xcalloc, xfree);
7112 +
7113    objfile_type_data = register_objfile_data ();
7114  
7115    add_setshow_zinteger_cmd ("overload", no_class, &overload_debug, _("\
7116 diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
7117 index 085270e..cb2b88e 100644
7118 --- a/gdb/gdbtypes.h
7119 +++ b/gdb/gdbtypes.h
7120 @@ -171,6 +171,7 @@ enum type_flag_value
7121    TYPE_FLAG_FIXED_INSTANCE = (1 << 15),
7122    TYPE_FLAG_STUB_SUPPORTED = (1 << 16),
7123    TYPE_FLAG_NOTTEXT = (1 << 17),
7124 +  TYPE_FLAG_GNU_IFUNC = (1 << 18),
7125  
7126    /* Used for error-checking.  */
7127    TYPE_FLAG_MIN = TYPE_FLAG_UNSIGNED
7128 @@ -214,6 +215,11 @@ enum type_instance_flag_value
7129  
7130  #define TYPE_TARGET_STUB(t)    (TYPE_MAIN_TYPE (t)->flag_target_stub)
7131  
7132 +/* Type needs to be evaluated on each CHECK_TYPEDEF and its results must not be
7133 +   sticky.  */
7134 +
7135 +#define TYPE_DYNAMIC(t)                (TYPE_MAIN_TYPE (t)->flag_dynamic)
7136 +
7137  /* Static type.  If this is set, the corresponding type had 
7138   * a static modifier.
7139   * Note: This may be unnecessary, since static data members
7140 @@ -271,6 +277,12 @@ enum type_instance_flag_value
7141  
7142  #define TYPE_NOTTEXT(t)                (TYPE_MAIN_TYPE (t)->flag_nottext)
7143  
7144 +/* Used only for TYPE_CODE_FUNC where it specifies the real function
7145 +   address is returned by this function call.  TYPE_TARGET_TYPE determines the
7146 +   final returned function type to be presented to user.  */
7147 +
7148 +#define TYPE_GNU_IFUNC(t)      (TYPE_MAIN_TYPE (t)->flag_gnu_ifunc)
7149 +
7150  /* Type owner.  If TYPE_OBJFILE_OWNED is true, the type is owned by
7151     the objfile retrieved as TYPE_OBJFILE.  Otherweise, the type is
7152     owned by an architecture; TYPE_OBJFILE is NULL in this case.  */
7153 @@ -285,6 +297,48 @@ enum type_instance_flag_value
7154  
7155  #define TYPE_DECLARED_CLASS(t) (TYPE_MAIN_TYPE (t)->flag_declared_class)
7156  
7157 +/* Define this type as being reclaimable during free_all_types.  Type is
7158 +   required to be have TYPE_OBJFILE set to NULL.  Setting this flag requires
7159 +   initializing TYPE_DISCARDABLE_AGE, see alloc_type_discardable.  */
7160 +
7161 +#define TYPE_DISCARDABLE(t)    (TYPE_MAIN_TYPE (t)->flag_discardable)
7162 +
7163 +/* Marker this type has been visited by the type_mark_used by this
7164 +   mark-and-sweep types garbage collecting pass.  Current pass is represented
7165 +   by TYPE_DISCARDABLE_AGE_CURRENT.  */
7166 +
7167 +#define TYPE_DISCARDABLE_AGE(t)        (TYPE_MAIN_TYPE (t)->flag_discardable_age)
7168 +
7169 +/* Is HIGH_BOUND a low-bound relative count (1) or the high bound itself (0)?  */
7170 +
7171 +#define TYPE_RANGE_HIGH_BOUND_IS_COUNT(range_type) \
7172 +  (TYPE_MAIN_TYPE (range_type)->flag_range_high_bound_is_count)
7173 +
7174 +/* Not allocated.  TYPE_ALLOCATED(t) must be NULL in such case.  If this flag
7175 +   is unset and TYPE_ALLOCATED(t) is NULL then the type is allocated.  If this
7176 +   flag is unset and TYPE_ALLOCATED(t) is not NULL then its DWARF block
7177 +   determines the actual allocation state.  */
7178 +
7179 +#define TYPE_NOT_ALLOCATED(t)  (TYPE_MAIN_TYPE (t)->flag_not_allocated)
7180 +
7181 +/* Not associated.  TYPE_ASSOCIATED(t) must be NULL in such case.  If this flag
7182 +   is unset and TYPE_ASSOCIATED(t) is NULL then the type is associated.  If
7183 +   this flag is unset and TYPE_ASSOCIATED(t) is not NULL then its DWARF block
7184 +   determines the actual association state.  */
7185 +
7186 +#define TYPE_NOT_ASSOCIATED(t) (TYPE_MAIN_TYPE (t)->flag_not_associated)
7187 +
7188 +/* Address of the actual data as for DW_AT_data_location.  Its dwarf block must
7189 +   not be evaluated unless both TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are
7190 +   false.  If TYPE_DATA_LOCATION_IS_ADDR set then TYPE_DATA_LOCATION_ADDR value
7191 +   is the actual data address value.  If unset and
7192 +   TYPE_DATA_LOCATION_DWARF_BLOCK is NULL then the value is the normal
7193 +   value_raw_address.  If unset and TYPE_DATA_LOCATION_DWARF_BLOCK is not NULL
7194 +   then its DWARF block determines the actual data address.  */
7195 +
7196 +#define TYPE_DATA_LOCATION_IS_ADDR(t) \
7197 +  (TYPE_MAIN_TYPE (t)->flag_data_location_is_addr)
7198 +
7199  /* Constant type.  If this is set, the corresponding type has a
7200   * const modifier.
7201   */
7202 @@ -389,11 +443,19 @@ struct main_type
7203    unsigned int flag_vector : 1;
7204    unsigned int flag_stub_supported : 1;
7205    unsigned int flag_nottext : 1;
7206 +  unsigned int flag_gnu_ifunc : 1;
7207    unsigned int flag_fixed_instance : 1;
7208    unsigned int flag_objfile_owned : 1;
7209    /* True if this type was declared with "class" rather than
7210       "struct".  */
7211    unsigned int flag_declared_class : 1;
7212 +  unsigned int flag_discardable : 1;
7213 +  unsigned int flag_discardable_age : 1;
7214 +  unsigned int flag_dynamic : 1;
7215 +  unsigned int flag_range_high_bound_is_count : 1;
7216 +  unsigned int flag_not_allocated : 1;
7217 +  unsigned int flag_not_associated : 1;
7218 +  unsigned int flag_data_location_is_addr : 1;
7219  
7220    /* A discriminant telling us which field of the type_specific union
7221       is being used for this type, if any.  */
7222 @@ -467,6 +529,20 @@ struct main_type
7223  
7224    struct type *target_type;
7225  
7226 +  /* For DW_AT_data_location.  */
7227 +  union
7228 +    {
7229 +      struct dwarf2_locexpr_baton *dwarf_block;
7230 +      CORE_ADDR addr;
7231 +    }
7232 +  data_location;
7233 +
7234 +  /* For DW_AT_allocated.  */
7235 +  struct dwarf2_locexpr_baton *allocated;
7236 +
7237 +  /* For DW_AT_associated.  */
7238 +  struct dwarf2_locexpr_baton *associated;
7239 +
7240    /* For structure and union types, a description of each field.
7241       For set and pascal array types, there is one "field",
7242       whose type is the domain type of the set or array.
7243 @@ -540,13 +616,34 @@ struct main_type
7244  
7245      struct range_bounds
7246      {
7247 +      struct
7248 +       {
7249 +         union
7250 +           {
7251 +             LONGEST constant;
7252 +             struct dwarf2_locexpr_baton *dwarf_block;
7253 +             struct
7254 +               {
7255 +                 struct dwarf2_loclist_baton *loclist;
7256 +                 struct type *type;
7257 +               }
7258 +             dwarf_loclist;
7259 +           }
7260 +         u;
7261 +         enum range_bound_kind
7262 +           {
7263 +             RANGE_BOUND_KIND_CONSTANT,
7264 +             RANGE_BOUND_KIND_DWARF_BLOCK,
7265 +             RANGE_BOUND_KIND_DWARF_LOCLIST
7266 +           }
7267 +         kind;
7268 +       }
7269        /* Low bound of range. */
7270 -
7271 -      LONGEST low;
7272 -
7273 +      low,
7274        /* High bound of range. */
7275 -
7276 -      LONGEST high;
7277 +      high,
7278 +      /* Byte stride of range. */
7279 +      byte_stride;
7280  
7281        /* Flags indicating whether the values of low and high are
7282           valid.  When true, the respective range value is
7283 @@ -889,9 +986,9 @@ extern void allocate_gnat_aux_type (struct type *);
7284  #define TYPE_POINTER_TYPE(thistype) (thistype)->pointer_type
7285  #define TYPE_REFERENCE_TYPE(thistype) (thistype)->reference_type
7286  #define TYPE_CHAIN(thistype) (thistype)->chain
7287 -/* Note that if thistype is a TYPEDEF type, you have to call check_typedef.
7288 -   But check_typedef does set the TYPE_LENGTH of the TYPEDEF type,
7289 -   so you only have to call check_typedef once.  Since allocate_value
7290 +/* Note that if thistype is a TYPEDEF, ARRAY or STRING type, you have to call
7291 +   check_typedef.  But check_typedef does set the TYPE_LENGTH of the TYPEDEF
7292 +   type, so you only have to call check_typedef once.  Since allocate_value
7293     calls check_typedef, TYPE_LENGTH (VALUE_TYPE (X)) is safe.  */
7294  #define TYPE_LENGTH(thistype) (thistype)->length
7295  /* Note that TYPE_CODE can be TYPE_CODE_TYPEDEF, so if you want the real
7296 @@ -899,11 +996,16 @@ extern void allocate_gnat_aux_type (struct type *);
7297  #define TYPE_CODE(thistype) TYPE_MAIN_TYPE(thistype)->code
7298  #define TYPE_NFIELDS(thistype) TYPE_MAIN_TYPE(thistype)->nfields
7299  #define TYPE_FIELDS(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.fields
7300 +#define TYPE_DATA_LOCATION_DWARF_BLOCK(thistype) TYPE_MAIN_TYPE (thistype)->data_location.dwarf_block
7301 +#define TYPE_DATA_LOCATION_ADDR(thistype) TYPE_MAIN_TYPE (thistype)->data_location.addr
7302 +#define TYPE_ALLOCATED(thistype) TYPE_MAIN_TYPE (thistype)->allocated
7303 +#define TYPE_ASSOCIATED(thistype) TYPE_MAIN_TYPE (thistype)->associated
7304  
7305  #define TYPE_INDEX_TYPE(type) TYPE_FIELD_TYPE (type, 0)
7306  #define TYPE_RANGE_DATA(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.bounds
7307 -#define TYPE_LOW_BOUND(range_type) TYPE_RANGE_DATA(range_type)->low
7308 -#define TYPE_HIGH_BOUND(range_type) TYPE_RANGE_DATA(range_type)->high
7309 +#define TYPE_LOW_BOUND(range_type) TYPE_RANGE_DATA(range_type)->low.u.constant
7310 +#define TYPE_HIGH_BOUND(range_type) TYPE_RANGE_DATA(range_type)->high.u.constant
7311 +#define TYPE_BYTE_STRIDE(range_type) TYPE_RANGE_DATA(range_type)->byte_stride.u.constant
7312  #define TYPE_LOW_BOUND_UNDEFINED(range_type) \
7313     TYPE_RANGE_DATA(range_type)->low_undefined
7314  #define TYPE_HIGH_BOUND_UNDEFINED(range_type) \
7315 @@ -920,7 +1022,14 @@ extern void allocate_gnat_aux_type (struct type *);
7316     (TYPE_HIGH_BOUND(TYPE_INDEX_TYPE((arraytype))))
7317  
7318  #define TYPE_ARRAY_LOWER_BOUND_VALUE(arraytype) \
7319 -   (TYPE_LOW_BOUND(TYPE_INDEX_TYPE((arraytype))))
7320 +  TYPE_LOW_BOUND (TYPE_INDEX_TYPE (arraytype))
7321 +
7322 +/* TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (arraytype)) with a fallback to the
7323 +   element size if no specific stride value is known.  */
7324 +#define TYPE_ARRAY_BYTE_STRIDE_VALUE(arraytype)                \
7325 +  (TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (arraytype)) == 0 \
7326 +   ? TYPE_LENGTH (TYPE_TARGET_TYPE (arraytype))                \
7327 +   : TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (arraytype)))
7328  
7329  /* C++ */
7330  
7331 @@ -1141,6 +1250,10 @@ struct builtin_type
7332       (*) () can server as a generic function pointer.  */
7333    struct type *builtin_func_ptr;
7334  
7335 +  /* `function returning pointer to function (returning void)' type.
7336 +     The final void return type is not significant for it.  */
7337 +  struct type *builtin_func_func;
7338 +
7339  
7340    /* Special-purpose types.  */
7341  
7342 @@ -1181,6 +1294,8 @@ struct objfile_type
7343  
7344    /* Types used for symbols with no debug information.  */
7345    struct type *nodebug_text_symbol;
7346 +  struct type *nodebug_text_gnu_ifunc_symbol;
7347 +  struct type *nodebug_got_plt_symbol;
7348    struct type *nodebug_data_symbol;
7349    struct type *nodebug_unknown_symbol;
7350    struct type *nodebug_tls_symbol;
7351 @@ -1328,6 +1443,18 @@ extern struct type *create_array_type (struct type *, struct type *,
7352                                        struct type *);
7353  extern struct type *lookup_array_range_type (struct type *, int, int);
7354  
7355 +extern CORE_ADDR type_range_any_field_internal (struct type *range_type,
7356 +                                               int fieldno);
7357 +
7358 +extern int type_range_high_bound_internal (struct type *range_type);
7359 +
7360 +extern int type_range_count_bound_internal (struct type *range_type);
7361 +
7362 +extern CORE_ADDR type_range_byte_stride_internal (struct type *range_type,
7363 +                                                 struct type *element_type);
7364 +
7365 +extern void finalize_type (struct type *type);
7366 +
7367  extern struct type *create_string_type (struct type *, struct type *,
7368                                         struct type *);
7369  extern struct type *lookup_string_range_type (struct type *, int, int);
7370 @@ -1370,6 +1497,8 @@ extern int is_public_ancestor (struct type *, struct type *);
7371  
7372  extern int is_unique_ancestor (struct type *, struct value *);
7373  
7374 +extern void type_mark_used (struct type *type);
7375 +
7376  /* Overload resolution */
7377  
7378  #define LENGTH_MATCH(bv) ((bv)->rank[0])
7379 @@ -1432,10 +1561,11 @@ extern void maintenance_print_type (char *, int);
7380  
7381  extern htab_t create_copied_types_hash (struct objfile *objfile);
7382  
7383 -extern struct type *copy_type_recursive (struct objfile *objfile,
7384 -                                        struct type *type,
7385 +extern struct type *copy_type_recursive (struct type *type,
7386                                          htab_t copied_types);
7387  
7388  extern struct type *copy_type (const struct type *type);
7389  
7390 +extern void free_all_types (void);
7391 +
7392  #endif /* GDBTYPES_H */
7393 diff --git a/gdb/i386-linux-nat.c b/gdb/i386-linux-nat.c
7394 index 4fce1ac..144a899 100644
7395 --- a/gdb/i386-linux-nat.c
7396 +++ b/gdb/i386-linux-nat.c
7397 @@ -747,6 +747,21 @@ i386_linux_dr_unset_status (unsigned long mask)
7398      }
7399  }
7400  
7401 +/* See i386_dr_low_type.detach.  Do not use wrappers i386_linux_dr_set_control
7402 +   or i386_linux_dr_reset_addr as they would modify the register cache
7403 +   (i386_linux_dr).  */
7404 +
7405 +static void
7406 +i386_linux_dr_detach (void)
7407 +{
7408 +  int regnum;
7409 +
7410 +  i386_linux_dr_set (inferior_ptid, DR_CONTROL, 0);
7411 +  i386_linux_dr_unset_status (~0UL);
7412 +  for (regnum = DR_FIRSTADDR; regnum <= DR_LASTADDR; regnum++)
7413 +    i386_linux_dr_set (inferior_ptid, regnum, 0);
7414 +}
7415 +
7416  static void
7417  i386_linux_new_thread (ptid_t ptid)
7418  {
7419 @@ -976,6 +991,7 @@ _initialize_i386_linux_nat (void)
7420    i386_dr_low.reset_addr = i386_linux_dr_reset_addr;
7421    i386_dr_low.get_status = i386_linux_dr_get_status;
7422    i386_dr_low.unset_status = i386_linux_dr_unset_status;
7423 +  i386_dr_low.detach = i386_linux_dr_detach;
7424    i386_set_debug_register_length (4);
7425  
7426    /* Override the default ptrace resume method.  */
7427 diff --git a/gdb/i386-nat.c b/gdb/i386-nat.c
7428 index eaa3644..0921c7e 100644
7429 --- a/gdb/i386-nat.c
7430 +++ b/gdb/i386-nat.c
7431 @@ -533,6 +533,17 @@ i386_remove_watchpoint (CORE_ADDR addr, int len, int type,
7432    return retval;
7433  }
7434  
7435 +/* See target_detach_watchpoints.  */
7436 +
7437 +static int
7438 +i386_detach_watchpoints (void)
7439 +{
7440 +  if (i386_dr_low.detach)
7441 +    i386_dr_low.detach ();
7442 +
7443 +  return 0;
7444 +}
7445 +
7446  /* Return non-zero if we can watch a memory region that starts at
7447     address ADDR and whose length is LEN bytes.  */
7448  
7449 @@ -685,6 +696,7 @@ i386_use_watchpoints (struct target_ops *t)
7450    t->to_stopped_data_address = i386_stopped_data_address;
7451    t->to_insert_watchpoint = i386_insert_watchpoint;
7452    t->to_remove_watchpoint = i386_remove_watchpoint;
7453 +  t->to_detach_watchpoints = i386_detach_watchpoints;
7454    t->to_insert_hw_breakpoint = i386_insert_hw_breakpoint;
7455    t->to_remove_hw_breakpoint = i386_remove_hw_breakpoint;
7456  }
7457 diff --git a/gdb/i386-nat.h b/gdb/i386-nat.h
7458 index 7317e7d..ea914a5 100644
7459 --- a/gdb/i386-nat.h
7460 +++ b/gdb/i386-nat.h
7461 @@ -62,6 +62,10 @@ extern void i386_use_watchpoints (struct target_ops *);
7462        unset_status             -- unset the specified bits of the debug
7463                                   status (DR6) register for all LWPs
7464  
7465 +      detach                   -- clear all debug registers of only the
7466 +                                 INFERIOR_PTID task without affecting any
7467 +                                 register caches.
7468 +
7469     Additionally, the native file should set the debug_register_length
7470     field to 4 or 8 depending on the number of bytes used for
7471     deubg registers.  */
7472 @@ -73,6 +77,7 @@ struct i386_dr_low_type
7473      void (*reset_addr) (int);
7474      unsigned long (*get_status) (void);
7475      void (*unset_status) (unsigned long);
7476 +    void (*detach) (void);
7477      int debug_register_length;
7478    };
7479  
7480 diff --git a/gdb/infcall.c b/gdb/infcall.c
7481 index 0c9a3af..957ec1d 100644
7482 --- a/gdb/infcall.c
7483 +++ b/gdb/infcall.c
7484 @@ -225,6 +225,56 @@ value_arg_coerce (struct gdbarch *gdbarch, struct value *arg,
7485    return value_cast (type, arg);
7486  }
7487  
7488 +/* Call gnu-ifunc (STT_GNU_IFUNC - a function returning addresss of a real
7489 +   function to call).  PC is the gnu-ifunc function entry.  Function returns
7490 +   function entry of the gnu-ifunc-resolved function to call.  If RETVAL_TYPEP
7491 +   is not NULL fill in *RETVAL_TYPEP with return type of the gnu-ifunc-resolved
7492 +   function to call.  Keep *RETVAL_TYPEP intact if the return type could not be
7493 +   found.  */
7494 +
7495 +static CORE_ADDR
7496 +gnu_ifunc_resolve (struct gdbarch *gdbarch, CORE_ADDR pc)
7497 +{
7498 +  char *name_at_pc;
7499 +  CORE_ADDR start_at_pc, address;
7500 +  struct type *func_func_type = builtin_type (gdbarch)->builtin_func_func;
7501 +  struct value *function, *address_val;
7502 +
7503 +  if (find_pc_partial_function (pc, &name_at_pc, &start_at_pc, NULL)
7504 +      && start_at_pc == pc)
7505 +    {
7506 +      if (resolve_gnu_ifunc (name_at_pc, &address))
7507 +       return address;
7508 +    }
7509 +  else
7510 +    name_at_pc = NULL;
7511 +
7512 +  function = allocate_value (func_func_type);
7513 +  set_value_address (function, pc);
7514 +
7515 +  /* gnu-ifuncs have no arguments.  FUNCTION is the function entry address
7516 +     while ADDRESS is a possible function descriptor..  */
7517 +  address_val = call_function_by_hand (function, 0, NULL);
7518 +  address = value_as_address (address_val);
7519 +
7520 +  if (name_at_pc)
7521 +    gnu_ifunc_record_cache (gdbarch, name_at_pc, address);
7522 +
7523 +  return gdbarch_convert_from_func_ptr_addr (gdbarch, address, &current_target);
7524 +}
7525 +
7526 +static struct type *
7527 +find_function_return_type (CORE_ADDR pc)
7528 +{
7529 +  struct symbol *sym = find_pc_function (pc);
7530 +
7531 +  if (sym != NULL && BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) == pc
7532 +      && SYMBOL_TYPE (sym) != NULL)
7533 +    return TYPE_TARGET_TYPE (SYMBOL_TYPE (sym));
7534 +
7535 +  return NULL;
7536 +}
7537 +
7538  /* Determine a function's address and its return type from its value.
7539     Calls error() if the function is not valid for calling.  */
7540  
7541 @@ -233,7 +283,6 @@ find_function_addr (struct value *function, struct type **retval_type)
7542  {
7543    struct type *ftype = check_typedef (value_type (function));
7544    struct gdbarch *gdbarch = get_type_arch (ftype);
7545 -  enum type_code code = TYPE_CODE (ftype);
7546    struct type *value_type = NULL;
7547    CORE_ADDR funaddr;
7548  
7549 @@ -241,24 +290,34 @@ find_function_addr (struct value *function, struct type **retval_type)
7550       part of it.  */
7551  
7552    /* Determine address to call.  */
7553 -  if (code == TYPE_CODE_FUNC || code == TYPE_CODE_METHOD)
7554 -    {
7555 -      funaddr = value_address (function);
7556 -      value_type = TYPE_TARGET_TYPE (ftype);
7557 -    }
7558 -  else if (code == TYPE_CODE_PTR)
7559 +  if (TYPE_CODE (ftype) == TYPE_CODE_FUNC
7560 +      || TYPE_CODE (ftype) == TYPE_CODE_METHOD)
7561 +    funaddr = value_address (function);
7562 +  else if (TYPE_CODE (ftype) == TYPE_CODE_PTR)
7563      {
7564        funaddr = value_as_address (function);
7565        ftype = check_typedef (TYPE_TARGET_TYPE (ftype));
7566        if (TYPE_CODE (ftype) == TYPE_CODE_FUNC
7567           || TYPE_CODE (ftype) == TYPE_CODE_METHOD)
7568 +       funaddr = gdbarch_convert_from_func_ptr_addr (gdbarch, funaddr,
7569 +                                                     &current_target);
7570 +    }
7571 +  if (TYPE_CODE (ftype) == TYPE_CODE_FUNC
7572 +      || TYPE_CODE (ftype) == TYPE_CODE_METHOD)
7573 +    {
7574 +      value_type = TYPE_TARGET_TYPE (ftype);
7575 +
7576 +      if (TYPE_GNU_IFUNC (ftype))
7577         {
7578 -         funaddr = gdbarch_convert_from_func_ptr_addr (gdbarch, funaddr,
7579 -                                                       &current_target);
7580 -         value_type = TYPE_TARGET_TYPE (ftype);
7581 +         funaddr = gnu_ifunc_resolve (gdbarch, funaddr);
7582 +
7583 +         /* Skip querying the function symbol if no RETVAL_TYPE has been
7584 +            asked for.  */
7585 +         if (retval_type)
7586 +           value_type = find_function_return_type (funaddr);
7587         }
7588      }
7589 -  else if (code == TYPE_CODE_INT)
7590 +  else if (TYPE_CODE (ftype) == TYPE_CODE_INT)
7591      {
7592        /* Handle the case of functions lacking debugging info.
7593           Their values are characters since their addresses are char */
7594 diff --git a/gdb/infcmd.c b/gdb/infcmd.c
7595 index c4cdb06..d213f6a 100644
7596 --- a/gdb/infcmd.c
7597 +++ b/gdb/infcmd.c
7598 @@ -822,7 +822,7 @@ nexti_command (char *count_string, int from_tty)
7599    step_1 (1, 1, count_string);
7600  }
7601  
7602 -static void
7603 +void
7604  delete_longjmp_breakpoint_cleanup (void *arg)
7605  {
7606    int thread = * (int *) arg;
7607 @@ -862,10 +862,13 @@ step_1 (int skip_subroutines, int single_inst, char *count_string)
7608  
7609    if (!single_inst || skip_subroutines)                /* leave si command alone */
7610      {
7611 +      struct thread_info *tp = inferior_thread ();
7612 +
7613        if (in_thread_list (inferior_ptid))
7614         thread = pid_to_thread_id (inferior_ptid);
7615  
7616        set_longjmp_breakpoint (thread);
7617 +      tp->initiating_frame = get_frame_id (get_current_frame ());
7618  
7619        make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
7620      }
7621 @@ -1219,6 +1222,15 @@ signal_command (char *signum_exp, int from_tty)
7622    proceed ((CORE_ADDR) -1, oursig, 0);
7623  }
7624  
7625 +/* A continuation callback for until_next_command.  */
7626 +
7627 +static void
7628 +until_next_continuation (void *arg)
7629 +{
7630 +  struct thread_info *tp = arg;
7631 +  delete_longjmp_breakpoint (tp->num);
7632 +}
7633 +
7634  /* Proceed until we reach a different source line with pc greater than
7635     our current one or exit the function.  We skip calls in both cases.
7636  
7637 @@ -1235,6 +1247,8 @@ until_next_command (int from_tty)
7638    struct symbol *func;
7639    struct symtab_and_line sal;
7640    struct thread_info *tp = inferior_thread ();
7641 +  int thread = tp->num;
7642 +  struct cleanup *old_chain;
7643  
7644    clear_proceed_status ();
7645    set_step_frame ();
7646 @@ -1270,7 +1284,19 @@ until_next_command (int from_tty)
7647  
7648    tp->step_multi = 0;          /* Only one call to proceed */
7649  
7650 +  set_longjmp_breakpoint (thread);
7651 +  tp->initiating_frame = get_frame_id (frame);
7652 +  old_chain = make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
7653 +
7654    proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
7655 +
7656 +  if (target_can_async_p () && is_running (inferior_ptid))
7657 +    {
7658 +      discard_cleanups (old_chain);
7659 +      add_continuation (tp, until_next_continuation, tp, NULL);
7660 +    }
7661 +  else
7662 +    do_cleanups (old_chain);
7663  }
7664  
7665  static void
7666 @@ -1463,6 +1489,7 @@ finish_command_continuation (void *arg)
7667    if (bs != NULL && tp->proceed_to_finish)
7668      observer_notify_normal_stop (bs, 1 /* print frame */);
7669    delete_breakpoint (a->breakpoint);
7670 +  delete_longjmp_breakpoint (inferior_thread ()->num);
7671  }
7672  
7673  static void
7674 @@ -1546,6 +1573,7 @@ finish_forward (struct symbol *function, struct frame_info *frame)
7675    struct breakpoint *breakpoint;
7676    struct cleanup *old_chain;
7677    struct finish_command_continuation_args *cargs;
7678 +  int thread = tp->num;
7679  
7680    sal = find_pc_line (get_frame_pc (frame), 0);
7681    sal.pc = get_frame_pc (frame);
7682 @@ -1556,6 +1584,10 @@ finish_forward (struct symbol *function, struct frame_info *frame)
7683  
7684    old_chain = make_cleanup_delete_breakpoint (breakpoint);
7685  
7686 +  set_longjmp_breakpoint (thread);
7687 +  tp->initiating_frame = get_frame_id (frame);
7688 +  make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
7689 +
7690    tp->proceed_to_finish = 1;    /* We want stop_registers, please...  */
7691    cargs = xmalloc (sizeof (*cargs));
7692  
7693 diff --git a/gdb/inferior.h b/gdb/inferior.h
7694 index 5abec68..e309277 100644
7695 --- a/gdb/inferior.h
7696 +++ b/gdb/inferior.h
7697 @@ -291,6 +291,8 @@ extern void interrupt_target_command (char *args, int from_tty);
7698  
7699  extern void interrupt_target_1 (int all_threads);
7700  
7701 +extern void delete_longjmp_breakpoint_cleanup (void *arg);
7702 +
7703  extern void detach_command (char *, int);
7704  
7705  extern void notice_new_inferior (ptid_t, int, int);
7706 diff --git a/gdb/infrun.c b/gdb/infrun.c
7707 index 54b1d9f..58d045a 100644
7708 --- a/gdb/infrun.c
7709 +++ b/gdb/infrun.c
7710 @@ -45,6 +45,8 @@
7711  #include "language.h"
7712  #include "solib.h"
7713  #include "main.h"
7714 +#include "dictionary.h"
7715 +#include "block.h"
7716  #include "gdb_assert.h"
7717  #include "mi/mi-common.h"
7718  #include "event-top.h"
7719 @@ -367,6 +369,7 @@ follow_fork (void)
7720       parent thread structure's run control related fields, not just these.
7721       Initialized to avoid "may be used uninitialized" warnings from gcc.  */
7722    struct breakpoint *step_resume_breakpoint = NULL;
7723 +  struct breakpoint *exception_resume_breakpoint = NULL;
7724    CORE_ADDR step_range_start = 0;
7725    CORE_ADDR step_range_end = 0;
7726    struct frame_id step_frame_id = { 0 };
7727 @@ -419,6 +422,8 @@ follow_fork (void)
7728             step_range_start = tp->step_range_start;
7729             step_range_end = tp->step_range_end;
7730             step_frame_id = tp->step_frame_id;
7731 +           exception_resume_breakpoint
7732 +             = clone_momentary_breakpoint (tp->exception_resume_breakpoint);
7733  
7734             /* For now, delete the parent's sr breakpoint, otherwise,
7735                parent/child sr breakpoints are considered duplicates,
7736 @@ -429,6 +434,7 @@ follow_fork (void)
7737             tp->step_range_start = 0;
7738             tp->step_range_end = 0;
7739             tp->step_frame_id = null_frame_id;
7740 +           delete_exception_resume_breakpoint (tp);
7741           }
7742  
7743         parent = inferior_ptid;
7744 @@ -470,6 +476,8 @@ follow_fork (void)
7745                     tp->step_range_start = step_range_start;
7746                     tp->step_range_end = step_range_end;
7747                     tp->step_frame_id = step_frame_id;
7748 +                   tp->exception_resume_breakpoint
7749 +                     = exception_resume_breakpoint;
7750                   }
7751                 else
7752                   {
7753 @@ -523,6 +531,9 @@ follow_inferior_reset_breakpoints (void)
7754    if (tp->step_resume_breakpoint)
7755      breakpoint_re_set_thread (tp->step_resume_breakpoint);
7756  
7757 +  if (tp->exception_resume_breakpoint)
7758 +    breakpoint_re_set_thread (tp->exception_resume_breakpoint);
7759 +
7760    /* Reinsert all breakpoints in the child.  The user may have set
7761       breakpoints after catching the fork, in which case those
7762       were never set in the child, but only in the parent.  This makes
7763 @@ -760,6 +771,7 @@ follow_exec (ptid_t pid, char *execd_pathname)
7764    /* If there was one, it's gone now.  We cannot truly step-to-next
7765       statement through an exec(). */
7766    th->step_resume_breakpoint = NULL;
7767 +  th->exception_resume_breakpoint = NULL;
7768    th->step_range_start = 0;
7769    th->step_range_end = 0;
7770  
7771 @@ -2190,6 +2202,8 @@ static void insert_step_resume_breakpoint_at_sal (struct gdbarch *gdbarch,
7772                                                   struct symtab_and_line sr_sal,
7773                                                   struct frame_id sr_id);
7774  static void insert_longjmp_resume_breakpoint (struct gdbarch *, CORE_ADDR);
7775 +static void check_exception_resume (struct execution_control_state *,
7776 +                                   struct frame_info *, struct symbol *);
7777  
7778  static void stop_stepping (struct execution_control_state *ecs);
7779  static void prepare_to_wait (struct execution_control_state *ecs);
7780 @@ -2313,6 +2327,7 @@ delete_step_resume_breakpoint_callback (struct thread_info *info, void *data)
7781      return 0;
7782  
7783    delete_step_resume_breakpoint (info);
7784 +  delete_exception_resume_breakpoint (info);
7785    return 0;
7786  }
7787  
7788 @@ -2337,6 +2352,7 @@ delete_step_thread_step_resume_breakpoint (void)
7789        struct thread_info *tp = inferior_thread ();
7790  
7791        delete_step_resume_breakpoint (tp);
7792 +      delete_exception_resume_breakpoint (tp);
7793      }
7794    else
7795      /* In all-stop mode, delete all step-resume and longjmp-resume
7796 @@ -3241,6 +3257,10 @@ handle_inferior_event (struct execution_control_state *ecs)
7797  
7798        stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
7799  
7800 +      /* Clear WATCHPOINT_TRIGGERED values from previous stop which could
7801 +        confuse bpstat_stop_status and bpstat_explains_signal.  */
7802 +      watchpoints_triggered (&ecs->ws);
7803 +
7804        ecs->event_thread->stop_bpstat
7805         = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
7806                               stop_pc, ecs->ptid);
7807 @@ -3328,6 +3348,10 @@ handle_inferior_event (struct execution_control_state *ecs)
7808  
7809        stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
7810  
7811 +      /* Clear WATCHPOINT_TRIGGERED values from previous stop which could
7812 +        confuse bpstat_stop_status and bpstat_explains_signal.  */
7813 +      watchpoints_triggered (&ecs->ws);
7814 +
7815        /* Do whatever is necessary to the parent branch of the vfork.  */
7816        handle_vfork_child_exec_or_exit (1);
7817  
7818 @@ -4076,23 +4100,33 @@ process_event_stop_test:
7819  
7820         ecs->event_thread->stepping_over_breakpoint = 1;
7821  
7822 -       if (!gdbarch_get_longjmp_target_p (gdbarch)
7823 -           || !gdbarch_get_longjmp_target (gdbarch, frame, &jmp_buf_pc))
7824 +       if (what.is_longjmp)
7825           {
7826 -           if (debug_infrun)
7827 -             fprintf_unfiltered (gdb_stdlog, "\
7828 +           if (!gdbarch_get_longjmp_target_p (gdbarch)
7829 +               || !gdbarch_get_longjmp_target (gdbarch,
7830 +                                               frame, &jmp_buf_pc))
7831 +             {
7832 +               if (debug_infrun)
7833 +                 fprintf_unfiltered (gdb_stdlog, "\
7834  infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n");
7835 -           keep_going (ecs);
7836 -           return;
7837 -         }
7838 +               keep_going (ecs);
7839 +               return;
7840 +             }
7841  
7842 -       /* We're going to replace the current step-resume breakpoint
7843 -          with a longjmp-resume breakpoint.  */
7844 -       delete_step_resume_breakpoint (ecs->event_thread);
7845 +           /* We're going to replace the current step-resume breakpoint
7846 +              with a longjmp-resume breakpoint.  */
7847 +           delete_step_resume_breakpoint (ecs->event_thread);
7848  
7849 -       /* Insert a breakpoint at resume address.  */
7850 -       insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc);
7851 +           /* Insert a breakpoint at resume address.  */
7852 +           insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc);
7853 +         }
7854 +       else
7855 +         {
7856 +           struct symbol *func = get_frame_function (frame);
7857  
7858 +           if (func)
7859 +             check_exception_resume (ecs, frame, func);
7860 +         }
7861         keep_going (ecs);
7862         return;
7863  
7864 @@ -4101,8 +4135,52 @@ infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n");
7865           fprintf_unfiltered (gdb_stdlog,
7866                               "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
7867  
7868 -       gdb_assert (ecs->event_thread->step_resume_breakpoint != NULL);
7869 -       delete_step_resume_breakpoint (ecs->event_thread);
7870 +       if (what.is_longjmp)
7871 +         {
7872 +           gdb_assert (ecs->event_thread->step_resume_breakpoint != NULL);
7873 +           delete_step_resume_breakpoint (ecs->event_thread);
7874 +         }
7875 +       else
7876 +         {
7877 +           /* There are several cases to consider.
7878 +
7879 +              1. The initiating frame no longer exists.  In this case
7880 +              we must stop, because the exception has gone too far.
7881 +
7882 +              2. The initiating frame exists, and is the same as the
7883 +              current frame.  We stop, because the exception has been
7884 +              caught.
7885 +
7886 +              3. The initiating frame exists and is different from
7887 +              the current frame.  This means the exception has been
7888 +              caught beneath the initiating frame, so keep going.  */
7889 +           struct frame_info *init_frame
7890 +             = frame_find_by_id (ecs->event_thread->initiating_frame);
7891 +
7892 +           gdb_assert (ecs->event_thread->exception_resume_breakpoint != NULL);
7893 +           delete_exception_resume_breakpoint (ecs->event_thread);
7894 +
7895 +           if (init_frame)
7896 +             {
7897 +               struct frame_id current_id
7898 +                 = get_frame_id (get_current_frame ());
7899 +               if (frame_id_eq (current_id,
7900 +                                ecs->event_thread->initiating_frame))
7901 +                 {
7902 +                   /* Case 2.  Fall through.  */
7903 +                 }
7904 +               else
7905 +                 {
7906 +                   /* Case 3.  */
7907 +                   keep_going (ecs);
7908 +                   return;
7909 +                 }
7910 +             }
7911 +
7912 +           /* For Cases 1 and 2, remove the step-resume breakpoint,
7913 +              if it exists.  */
7914 +           delete_step_resume_breakpoint (ecs->event_thread);
7915 +         }
7916  
7917         ecs->event_thread->stop_step = 1;
7918         print_stop_reason (END_STEPPING_RANGE, 0);
7919 @@ -5070,6 +5148,97 @@ insert_longjmp_resume_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc)
7920      set_momentary_breakpoint_at_pc (gdbarch, pc, bp_longjmp_resume);
7921  }
7922  
7923 +/* Insert an exception resume breakpoint.  TP is the thread throwing
7924 +   the exception.  The block B is the block of the unwinder debug hook
7925 +   function.  FRAME is the frame corresponding to the call to this
7926 +   function.  SYM is the symbol of the function argument holding the
7927 +   target PC of the exception.  */
7928 +
7929 +static void
7930 +insert_exception_resume_breakpoint (struct thread_info *tp,
7931 +                                   struct block *b,
7932 +                                   struct frame_info *frame,
7933 +                                   struct symbol *sym)
7934 +{
7935 +  struct gdb_exception e;
7936 +
7937 +  /* We want to ignore errors here.  */
7938 +  TRY_CATCH (e, RETURN_MASK_ALL)
7939 +    {
7940 +      struct symbol *vsym;
7941 +      struct value *value;
7942 +      CORE_ADDR handler;
7943 +      struct breakpoint *bp;
7944 +
7945 +      vsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym), b, VAR_DOMAIN, NULL);
7946 +      value = read_var_value (vsym, frame);
7947 +      /* If the value was optimized out, revert to the old behavior.  */
7948 +      if (! value_optimized_out (value))
7949 +       {
7950 +         handler = value_as_address (value);
7951 +
7952 +         if (debug_infrun)
7953 +           fprintf_unfiltered (gdb_stdlog,
7954 +                               "infrun: exception resume at %lx\n",
7955 +                               (unsigned long) handler);
7956 +
7957 +         bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame),
7958 +                                              handler, bp_exception_resume);
7959 +         bp->thread = tp->num;
7960 +         inferior_thread ()->exception_resume_breakpoint = bp;
7961 +       }
7962 +    }
7963 +}
7964 +
7965 +/* This is called when an exception has been intercepted.  Check to
7966 +   see whether the exception's destination is of interest, and if so,
7967 +   set an exception resume breakpoint there.  */
7968 +
7969 +static void
7970 +check_exception_resume (struct execution_control_state *ecs,
7971 +                       struct frame_info *frame, struct symbol *func)
7972 +{
7973 +  struct gdb_exception e;
7974 +
7975 +  TRY_CATCH (e, RETURN_MASK_ALL)
7976 +    {
7977 +      struct block *b;
7978 +      struct dict_iterator iter;
7979 +      struct symbol *sym;
7980 +      int argno = 0;
7981 +
7982 +      /* The exception breakpoint is a thread-specific breakpoint on
7983 +        the unwinder's debug hook, declared as:
7984 +        
7985 +        void _Unwind_DebugHook (void *cfa, void *handler);
7986 +        
7987 +        The CFA argument indicates the frame to which control is
7988 +        about to be transferred.  HANDLER is the destination PC.
7989 +        
7990 +        We ignore the CFA and set a temporary breakpoint at HANDLER.
7991 +        This is not extremely efficient but it avoids issues in gdb
7992 +        with computing the DWARF CFA, and it also works even in weird
7993 +        cases such as throwing an exception from inside a signal
7994 +        handler.  */
7995 +
7996 +      b = SYMBOL_BLOCK_VALUE (func);
7997 +      ALL_BLOCK_SYMBOLS (b, iter, sym)
7998 +       {
7999 +         if (!SYMBOL_IS_ARGUMENT (sym))
8000 +           continue;
8001 +
8002 +         if (argno == 0)
8003 +           ++argno;
8004 +         else
8005 +           {
8006 +             insert_exception_resume_breakpoint (ecs->event_thread,
8007 +                                                 b, frame, sym);
8008 +             break;
8009 +           }
8010 +       }
8011 +    }
8012 +}
8013 +
8014  static void
8015  stop_stepping (struct execution_control_state *ecs)
8016  {
8017 diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
8018 index 93adfcd..34412a6 100644
8019 --- a/gdb/linux-nat.c
8020 +++ b/gdb/linux-nat.c
8021 @@ -2587,6 +2587,39 @@ linux_nat_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p)
8022    return lp->stopped_data_address_p;
8023  }
8024  
8025 +/* In `set follow-fork-mode child' with multithreaded parent we need to detach
8026 +   watchpoints from all the LWPs.  In such case INFERIOR_PTID will be the
8027 +   non-threaded new child while LWP_LIST will still contain all the threads of
8028 +   the parent being detached.  */
8029 +
8030 +static int
8031 +linux_nat_detach_watchpoints (void)
8032 +{
8033 +  struct lwp_info *lp;
8034 +  int found = 0, retval = 0;
8035 +  ptid_t filter = pid_to_ptid (ptid_get_pid (inferior_ptid));
8036 +  struct cleanup *old_chain = save_inferior_ptid ();
8037 +
8038 +  for (lp = lwp_list; lp; lp = lp->next)
8039 +    if (ptid_match (lp->ptid, filter))
8040 +      {
8041 +       inferior_ptid = lp->ptid;
8042 +       retval |= linux_ops->to_detach_watchpoints ();
8043 +       found = 1;
8044 +      }
8045 +
8046 +  do_cleanups (old_chain);
8047 +
8048 +  if (!found)
8049 +    {
8050 +      gdb_assert (!is_lwp (inferior_ptid));
8051 +
8052 +      retval |= linux_ops->to_detach_watchpoints ();
8053 +    }
8054 +
8055 +  return retval;
8056 +}
8057 +
8058  /* Wait until LP is stopped.  */
8059  
8060  static int
8061 @@ -5606,6 +5639,8 @@ linux_nat_add_target (struct target_ops *t)
8062    t->to_thread_address_space = linux_nat_thread_address_space;
8063    t->to_stopped_by_watchpoint = linux_nat_stopped_by_watchpoint;
8064    t->to_stopped_data_address = linux_nat_stopped_data_address;
8065 +  if (linux_ops->to_detach_watchpoints)
8066 +    t->to_detach_watchpoints = linux_nat_detach_watchpoints;
8067  
8068    t->to_can_async_p = linux_nat_can_async_p;
8069    t->to_is_async_p = linux_nat_is_async_p;
8070 diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
8071 index 07fd67c..2524250 100644
8072 --- a/gdb/linux-tdep.c
8073 +++ b/gdb/linux-tdep.c
8074 @@ -23,6 +23,8 @@
8075  #include "auxv.h"
8076  #include "target.h"
8077  #include "elf/common.h"
8078 +#include "value.h"
8079 +#include "infcall.h"
8080  
8081  /* This function is suitable for architectures that don't
8082     extend/override the standard siginfo structure.  */
8083 diff --git a/gdb/main.c b/gdb/main.c
8084 index bfd1213..72faabd 100644
8085 --- a/gdb/main.c
8086 +++ b/gdb/main.c
8087 @@ -39,6 +39,7 @@
8088  
8089  #include "interps.h"
8090  #include "main.h"
8091 +#include "python/python.h"
8092  #include "source.h"
8093  #include "cli/cli-cmds.h"
8094  #include "python/python.h"
8095 @@ -259,6 +260,8 @@ captured_main (void *data)
8096    char *cdarg = NULL;
8097    char *ttyarg = NULL;
8098  
8099 +  int python_script = 0;
8100 +
8101    /* These are static so that we can take their address in an initializer.  */
8102    static int print_help;
8103    static int print_version;
8104 @@ -443,10 +446,14 @@ captured_main (void *data)
8105        {"args", no_argument, &set_args, 1},
8106        {"l", required_argument, 0, 'l'},
8107        {"return-child-result", no_argument, &return_child_result, 1},
8108 +#if HAVE_PYTHON
8109 +      {"python", no_argument, 0, 'P'},
8110 +      {"P", no_argument, 0, 'P'},
8111 +#endif
8112        {0, no_argument, 0, 0}
8113      };
8114  
8115 -    while (1)
8116 +    while (!python_script)
8117        {
8118         int option_index;
8119  
8120 @@ -464,6 +471,9 @@ captured_main (void *data)
8121           case 0:
8122             /* Long option that just sets a flag.  */
8123             break;
8124 +         case 'P':
8125 +           python_script = 1;
8126 +           break;
8127           case OPT_SE:
8128             symarg = optarg;
8129             execarg = optarg;
8130 @@ -650,7 +660,31 @@ extern int gdbtk_test (char *);
8131  
8132    /* Now that gdb_init has created the initial inferior, we're in position
8133       to set args for that inferior.  */
8134 -  if (set_args)
8135 +  if (python_script)
8136 +    {
8137 +      /* The first argument is a python script to evaluate, and
8138 +        subsequent arguments are passed to the script for
8139 +        processing there.  */
8140 +      if (optind >= argc)
8141 +       {
8142 +         fprintf_unfiltered (gdb_stderr,
8143 +                             _("%s: Python script file name required\n"),
8144 +                             argv[0]);
8145 +         exit (1);
8146 +       }
8147 +
8148 +      /* FIXME: should handle inferior I/O intelligently here.
8149 +        E.g., should be possible to run gdb in pipeline and have
8150 +        Python (and gdb) output go to stderr or file; and if a
8151 +        prompt is needed, open the tty.  */
8152 +      quiet = 1;
8153 +      /* FIXME: should read .gdbinit if, and only if, a prompt is
8154 +        requested by the script.  Though... maybe this is not
8155 +        ideal?  */
8156 +      /* FIXME: likewise, reading in history.  */
8157 +      inhibit_gdbinit = 1;
8158 +    }
8159 +  else if (set_args)
8160      {
8161        /* The remaining options are the command-line options for the
8162          inferior.  The first one is the sym/exec file, and the rest
8163 @@ -890,7 +924,8 @@ Can't attach to process and specify a core file at the same time."));
8164    xfree (cmdarg);
8165  
8166    /* Read in the old history after all the command files have been read. */
8167 -  init_history ();
8168 +  if (!python_script)
8169 +    init_history ();
8170  
8171    if (batch_flag)
8172      {
8173 @@ -901,13 +936,25 @@ Can't attach to process and specify a core file at the same time."));
8174    /* Show time and/or space usage.  */
8175    do_cleanups (pre_stat_chain);
8176  
8177 -  /* NOTE: cagney/1999-11-07: There is probably no reason for not
8178 -     moving this loop and the code found in captured_command_loop()
8179 -     into the command_loop() proper.  The main thing holding back that
8180 -     change - SET_TOP_LEVEL() - has been eliminated. */
8181 -  while (1)
8182 +#if HAVE_PYTHON
8183 +  if (python_script)
8184      {
8185 -      catch_errors (captured_command_loop, 0, "", RETURN_MASK_ALL);
8186 +      extern int pagination_enabled;
8187 +      pagination_enabled = 0;
8188 +      run_python_script (argc - optind, &argv[optind]);
8189 +      return 1;
8190 +    }
8191 +  else
8192 +#endif
8193 +    {
8194 +      /* NOTE: cagney/1999-11-07: There is probably no reason for not
8195 +        moving this loop and the code found in captured_command_loop()
8196 +        into the command_loop() proper.  The main thing holding back that
8197 +        change - SET_TOP_LEVEL() - has been eliminated. */
8198 +      while (1)
8199 +       {
8200 +         catch_errors (captured_command_loop, 0, "", RETURN_MASK_ALL);
8201 +       }
8202      }
8203    /* No exit -- exit is through quit_command.  */
8204  }
8205 @@ -939,7 +986,12 @@ print_gdb_help (struct ui_file *stream)
8206    fputs_unfiltered (_("\
8207  This is the GNU debugger.  Usage:\n\n\
8208      gdb [options] [executable-file [core-file or process-id]]\n\
8209 -    gdb [options] --args executable-file [inferior-arguments ...]\n\n\
8210 +    gdb [options] --args executable-file [inferior-arguments ...]\n"), stream);
8211 +#if HAVE_PYTHON
8212 +  fputs_unfiltered (_("\
8213 +    gdb [options] [--python|-P] script-file [script-arguments ...]\n"), stream);
8214 +#endif
8215 +  fputs_unfiltered (_("\n\
8216  Options:\n\n\
8217  "), stream);
8218    fputs_unfiltered (_("\
8219 @@ -977,7 +1029,13 @@ Options:\n\n\
8220    --nw              Do not use a window interface.\n\
8221    --nx               Do not read "), stream);
8222    fputs_unfiltered (gdbinit, stream);
8223 -  fputs_unfiltered (_(" file.\n\
8224 +  fputs_unfiltered (_(" file.\n"), stream);
8225 +#if HAVE_PYTHON
8226 +  fputs_unfiltered (_("\
8227 +  --python, -P       Following argument is Python script file; remaining\n\
8228 +                     arguments are passed to script.\n"), stream);
8229 +#endif
8230 +  fputs_unfiltered (_("\
8231    --quiet            Do not print version number on startup.\n\
8232    --readnow          Fully read symbol files on first access.\n\
8233  "), stream);
8234 diff --git a/gdb/maint.c b/gdb/maint.c
8235 index 28fd610..4e21476 100644
8236 --- a/gdb/maint.c
8237 +++ b/gdb/maint.c
8238 @@ -909,4 +909,12 @@ When enabled GDB is profiled."),
8239                            show_maintenance_profile_p,
8240                            &maintenance_set_cmdlist,
8241                            &maintenance_show_cmdlist);
8242 +  add_setshow_filename_cmd ("gdb_datadir", class_maintenance,
8243 +                           &gdb_datadir, _("Set GDB's datadir path."),
8244 +                           _("Show GDB's datadir path."),
8245 +                           _("\
8246 +When set, GDB uses the specified path to search for data files."),
8247 +                           NULL, NULL,
8248 +                           &maintenance_set_cmdlist,
8249 +                           &maintenance_show_cmdlist);
8250  }
8251 diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
8252 index 310ade9..d8710a1 100644
8253 --- a/gdb/mi/mi-cmd-var.c
8254 +++ b/gdb/mi/mi-cmd-var.c
8255 @@ -702,7 +702,6 @@ mi_cmd_var_update (char *command, char **argv, int argc)
8256      }
8257    else
8258      {
8259 -      /* Get varobj handle, if a valid var obj name was specified */
8260        struct varobj *var = varobj_get_handle (name);
8261  
8262        varobj_update_one (var, print_values, 1 /* explicit */);
8263 diff --git a/gdb/minsyms.c b/gdb/minsyms.c
8264 index cb4545c..92d4027 100644
8265 --- a/gdb/minsyms.c
8266 +++ b/gdb/minsyms.c
8267 @@ -337,8 +337,9 @@ lookup_minimal_symbol_text (const char *name, struct objfile *objf)
8268                msymbol = msymbol->hash_next)
8269             {
8270               if (strcmp (SYMBOL_LINKAGE_NAME (msymbol), name) == 0 &&
8271 -                 (MSYMBOL_TYPE (msymbol) == mst_text ||
8272 -                  MSYMBOL_TYPE (msymbol) == mst_file_text))
8273 +                 (MSYMBOL_TYPE (msymbol) == mst_text
8274 +                  || MSYMBOL_TYPE (msymbol) == mst_text_gnu_ifunc
8275 +                  || MSYMBOL_TYPE (msymbol) == mst_file_text))
8276                 {
8277                   switch (MSYMBOL_TYPE (msymbol))
8278                     {
8279 @@ -700,6 +701,16 @@ lookup_minimal_symbol_by_pc (CORE_ADDR pc)
8280    return lookup_minimal_symbol_by_pc_section (pc, NULL);
8281  }
8282  
8283 +/* Return non-zero iff PC is in function implementing gnu-ifunc selection.  */
8284 +
8285 +int
8286 +in_gnu_ifunc_stub (CORE_ADDR pc)
8287 +{
8288 +  struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
8289 +
8290 +  return msymbol && MSYMBOL_TYPE (msymbol) == mst_text_gnu_ifunc;
8291 +}
8292 +
8293  /* Find the minimal symbol named NAME, and return both the minsym
8294     struct and its objfile.  This only checks the linkage name.  Sets
8295     *OBJFILE_P and returns the minimal symbol, if it is found.  If it
8296 @@ -769,6 +780,7 @@ prim_record_minimal_symbol (const char *name, CORE_ADDR address,
8297    switch (ms_type)
8298      {
8299      case mst_text:
8300 +    case mst_text_gnu_ifunc:
8301      case mst_file_text:
8302      case mst_solib_trampoline:
8303        section = SECT_OFF_TEXT (objfile);
8304 @@ -1235,7 +1247,8 @@ find_solib_trampoline_target (struct frame_info *frame, CORE_ADDR pc)
8305      {
8306        ALL_MSYMBOLS (objfile, msymbol)
8307        {
8308 -       if (MSYMBOL_TYPE (msymbol) == mst_text
8309 +       if ((MSYMBOL_TYPE (msymbol) == mst_text
8310 +           || MSYMBOL_TYPE (msymbol) == mst_text_gnu_ifunc)
8311             && strcmp (SYMBOL_LINKAGE_NAME (msymbol),
8312                        SYMBOL_LINKAGE_NAME (tsymbol)) == 0)
8313           return SYMBOL_VALUE_ADDRESS (msymbol);
8314 diff --git a/gdb/p-lang.c b/gdb/p-lang.c
8315 index 08738ac..64d2e9f 100644
8316 --- a/gdb/p-lang.c
8317 +++ b/gdb/p-lang.c
8318 @@ -222,7 +222,11 @@ pascal_printstr (struct ui_file *stream, struct type *type,
8319    unsigned int things_printed = 0;
8320    int in_quotes = 0;
8321    int need_comma = 0;
8322 -  int width = TYPE_LENGTH (type);
8323 +  int width;
8324 +
8325 +  /* Preserve TYPE's original type, just set its LENGTH.  */
8326 +  check_typedef (type);
8327 +  width = TYPE_LENGTH (type);
8328  
8329    /* If the string was not truncated due to `set print elements', and
8330       the last byte of it is a null, we don't print that, in traditional C
8331 diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c
8332 index 4d39bed..d0ddebc 100644
8333 --- a/gdb/p-valprint.c
8334 +++ b/gdb/p-valprint.c
8335 @@ -38,6 +38,7 @@
8336  #include "p-lang.h"
8337  #include "cp-abi.h"
8338  #include "cp-support.h"
8339 +#include "dwarf2loc.h"
8340  \f
8341  
8342  
8343 @@ -68,8 +69,27 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
8344    struct type *char_type;
8345    LONGEST val;
8346    CORE_ADDR addr;
8347 +  struct cleanup *back_to;
8348 +  struct type *saved_type = type;
8349 +  CORE_ADDR saved_address = address;
8350 +  
8351 +  back_to = make_cleanup (null_cleanup, 0);
8352 +  type = object_address_get_data (type, &address);
8353 +  if (type == NULL)
8354 +    {
8355 +      fputs_filtered (object_address_data_not_valid (saved_type), stream);
8356 +      gdb_flush (stream);
8357 +      do_cleanups (back_to);
8358 +      return 0;
8359 +    }
8360 +  if (address != saved_address)
8361 +    {
8362 +      size_t length = TYPE_LENGTH (type);
8363  
8364 -  CHECK_TYPEDEF (type);
8365 +      valaddr = xmalloc (length);
8366 +      make_cleanup (xfree, (gdb_byte *) valaddr);
8367 +      read_memory (address, (gdb_byte *) valaddr, length);
8368 +    }
8369    switch (TYPE_CODE (type))
8370      {
8371      case TYPE_CODE_ARRAY:
8372 @@ -125,8 +145,9 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
8373                 {
8374                   i = 0;
8375                 }
8376 -             val_print_array_elements (type, valaddr + embedded_offset, address, stream,
8377 -                                       recurse, original_value, options, i);
8378 +             val_print_array_elements (saved_type, valaddr + embedded_offset,
8379 +                                       saved_address, stream, recurse,
8380 +                                       original_value, options, i);
8381               fprintf_filtered (stream, "}");
8382             }
8383           break;
8384 @@ -164,6 +185,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
8385           /* Try to print what function it points to.  */
8386           print_address_demangle (gdbarch, addr, stream, demangle);
8387           /* Return value is irrelevant except for string pointers.  */
8388 +         do_cleanups (back_to);
8389           return (0);
8390         }
8391  
8392 @@ -252,6 +274,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
8393        /* Return number of characters printed, including the terminating
8394          '\0' if we reached the end.  val_print_string takes care including
8395          the terminating '\0' if necessary.  */
8396 +      do_cleanups (back_to);
8397        return i;
8398  
8399        break;
8400 @@ -554,6 +577,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
8401        error (_("Invalid pascal type code %d in symbol table."), TYPE_CODE (type));
8402      }
8403    gdb_flush (stream);
8404 +  do_cleanups (back_to);
8405    return (0);
8406  }
8407  \f
8408 diff --git a/gdb/parse.c b/gdb/parse.c
8409 index c885c6a..cbf9c65 100644
8410 --- a/gdb/parse.c
8411 +++ b/gdb/parse.c
8412 @@ -487,9 +487,21 @@ write_exp_msymbol (struct minimal_symbol *msymbol)
8413    pc = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, &current_target);
8414    if (pc != addr)
8415      {
8416 +      struct minimal_symbol *ifunc_msym = lookup_minimal_symbol_by_pc (pc);
8417 +
8418        /* In this case, assume we have a code symbol instead of
8419          a data symbol.  */
8420 -      type = mst_text;
8421 +
8422 +      if (ifunc_msym != NULL && MSYMBOL_TYPE (ifunc_msym) == mst_text_gnu_ifunc
8423 +         && SYMBOL_VALUE_ADDRESS (ifunc_msym) == pc)
8424 +       {
8425 +         /* A function descriptor has been resolved but PC is still in the
8426 +            gnu-ifunc resolver body (such as because inferior does not run to
8427 +            be able to call it).  */
8428 +         type = mst_text_gnu_ifunc;
8429 +       }
8430 +      else
8431 +       type = mst_text;
8432        section = NULL;
8433        addr = pc;
8434      }
8435 @@ -521,6 +533,11 @@ write_exp_msymbol (struct minimal_symbol *msymbol)
8436        write_exp_elt_type (objfile_type (objfile)->nodebug_text_symbol);
8437        break;
8438  
8439 +    case mst_text_gnu_ifunc:
8440 +      write_exp_elt_type (objfile_type (objfile)
8441 +                                              ->nodebug_text_gnu_ifunc_symbol);
8442 +      break;
8443 +
8444      case mst_data:
8445      case mst_file_data:
8446      case mst_bss:
8447 @@ -528,6 +545,10 @@ write_exp_msymbol (struct minimal_symbol *msymbol)
8448        write_exp_elt_type (objfile_type (objfile)->nodebug_data_symbol);
8449        break;
8450  
8451 +    case mst_slot_got_plt:
8452 +      write_exp_elt_type (objfile_type (objfile)->nodebug_got_plt_symbol);
8453 +      break;
8454 +
8455      default:
8456        write_exp_elt_type (objfile_type (objfile)->nodebug_unknown_symbol);
8457        break;
8458 @@ -1412,6 +1433,7 @@ parser_fprintf (FILE *x, const char *y, ...)
8459  
8460  int
8461  operator_check_standard (struct expression *exp, int pos,
8462 +                        int (*type_func) (struct type *type, void *data),
8463                          int (*objfile_func) (struct objfile *objfile,
8464                                               void *data),
8465                          void *data)
8466 @@ -1453,7 +1475,7 @@ operator_check_standard (struct expression *exp, int pos,
8467             struct type *type = elts[pos + 2 + arg].type;
8468             struct objfile *objfile = TYPE_OBJFILE (type);
8469  
8470 -           if (objfile && (*objfile_func) (objfile, data))
8471 +           if (objfile && objfile_func && (*objfile_func) (objfile, data))
8472               return 1;
8473           }
8474        }
8475 @@ -1471,7 +1493,8 @@ operator_check_standard (struct expression *exp, int pos,
8476  
8477         /* Check objfile where the variable itself is placed.
8478            SYMBOL_OBJ_SECTION (symbol) may be NULL.  */
8479 -       if ((*objfile_func) (SYMBOL_SYMTAB (symbol)->objfile, data))
8480 +       if (objfile_func
8481 +           && (*objfile_func) (SYMBOL_SYMTAB (symbol)->objfile, data))
8482           return 1;
8483  
8484         /* Check objfile where is placed the code touching the variable.  */
8485 @@ -1484,24 +1507,27 @@ operator_check_standard (struct expression *exp, int pos,
8486  
8487    /* Invoke callbacks for TYPE and OBJFILE if they were set as non-NULL.  */
8488  
8489 -  if (type && TYPE_OBJFILE (type)
8490 +  if (type && type_func && (*type_func) (type, data))
8491 +    return 1;
8492 +  if (type && TYPE_OBJFILE (type) && objfile_func
8493        && (*objfile_func) (TYPE_OBJFILE (type), data))
8494      return 1;
8495 -  if (objfile && (*objfile_func) (objfile, data))
8496 +  if (objfile && objfile_func && (*objfile_func) (objfile, data))
8497      return 1;
8498  
8499    return 0;
8500  }
8501  
8502 -/* Call OBJFILE_FUNC for any TYPE and OBJFILE found being referenced by EXP.
8503 -   The functions are never called with NULL OBJFILE.  Functions get passed an
8504 -   arbitrary caller supplied DATA pointer.  If any of the functions returns
8505 -   non-zero value then (any other) non-zero value is immediately returned to
8506 -   the caller.  Otherwise zero is returned after iterating through whole EXP.
8507 -   */
8508 +/* Call TYPE_FUNC and OBJFILE_FUNC for any TYPE and OBJFILE found being
8509 +   referenced by EXP.  The functions are never called with NULL TYPE or NULL
8510 +   OBJFILE.  Functions get passed an arbitrary caller supplied DATA pointer.
8511 +   If any of the functions returns non-zero value then (any other) non-zero
8512 +   value is immediately returned to the caller.  Otherwise zero is returned
8513 +   after iterating through whole EXP.  */
8514  
8515  static int
8516  exp_iterate (struct expression *exp,
8517 +            int (*type_func) (struct type *type, void *data),
8518              int (*objfile_func) (struct objfile *objfile, void *data),
8519              void *data)
8520  {
8521 @@ -1516,7 +1542,9 @@ exp_iterate (struct expression *exp,
8522  
8523        pos = endpos - oplen;
8524        if (exp->language_defn->la_exp_desc->operator_check (exp, pos,
8525 -                                                          objfile_func, data))
8526 +                                                          type_func,
8527 +                                                          objfile_func,
8528 +                                                          data))
8529         return 1;
8530  
8531        endpos = pos;
8532 @@ -1547,7 +1575,26 @@ exp_uses_objfile (struct expression *exp, struct objfile *objfile)
8533  {
8534    gdb_assert (objfile->separate_debug_objfile_backlink == NULL);
8535  
8536 -  return exp_iterate (exp, exp_uses_objfile_iter, objfile);
8537 +  return exp_iterate (exp, NULL, exp_uses_objfile_iter, objfile);
8538 +}
8539 +
8540 +/* Helper for exp_types_mark_used.  */
8541 +
8542 +static int
8543 +exp_types_mark_used_iter (struct type *type, void *unused)
8544 +{
8545 +  type_mark_used (type);
8546 +
8547 +  /* Continue the traversal.  */
8548 +  return 0;
8549 +}
8550 +
8551 +/* Call type_mark_used for any type contained in EXP.  */
8552 +
8553 +void
8554 +exp_types_mark_used (struct expression *exp)
8555 +{
8556 +  exp_iterate (exp, exp_types_mark_used_iter, NULL, NULL);
8557  }
8558  
8559  void
8560 diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h
8561 index bb79ae1..fbbd600 100644
8562 --- a/gdb/parser-defs.h
8563 +++ b/gdb/parser-defs.h
8564 @@ -194,6 +194,8 @@ extern void operator_length_standard (const struct expression *, int, int *,
8565                                       int *);
8566  
8567  extern int operator_check_standard (struct expression *exp, int pos,
8568 +                                   int (*type_func) (struct type *type,
8569 +                                                     void *data),
8570                                     int (*objfile_func)
8571                                       (struct objfile *objfile, void *data),
8572                                     void *data);
8573 @@ -285,6 +287,7 @@ struct exp_descriptor
8574         value should be immediately returned to the caller.  Otherwise zero
8575         should be returned.  */
8576      int (*operator_check) (struct expression *exp, int pos,
8577 +                          int (*type_func) (struct type *type, void *data),
8578                            int (*objfile_func) (struct objfile *objfile,
8579                                                 void *data),
8580                            void *data);
8581 @@ -323,4 +326,8 @@ extern void parser_fprintf (FILE *, const char *, ...) ATTRIBUTE_PRINTF (2, 3);
8582  
8583  extern int exp_uses_objfile (struct expression *exp, struct objfile *objfile);
8584  
8585 +extern int exp_uses_objfile (struct expression *exp, struct objfile *objfile);
8586 +
8587 +extern void exp_types_mark_used (struct expression *exp);
8588 +
8589  #endif /* PARSER_DEFS_H */
8590 diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c
8591 index 18ddee7..652b02a 100644
8592 --- a/gdb/ppc-linux-nat.c
8593 +++ b/gdb/ppc-linux-nat.c
8594 @@ -2010,6 +2010,24 @@ ppc_linux_remove_watchpoint (CORE_ADDR addr, int len, int rw,
8595    return ret;
8596  }
8597  
8598 +/* See target_detach_watchpoints.  Do not use wrapper
8599 +   ppc_linux_remove_watchpoint as it would modify the register cache
8600 +   (saved_dabr_value).  */
8601 +
8602 +static int
8603 +ppc_linux_detach_watchpoints (void)
8604 +{
8605 +  pid_t tid;
8606 +
8607 +  tid = TIDGET (inferior_ptid);
8608 +  if (tid == 0)
8609 +    tid = PIDGET (inferior_ptid);
8610 +
8611 +  if (ptrace (PTRACE_SET_DEBUGREG, tid, NULL, NULL) < 0)
8612 +    return -1;
8613 +  return 0;
8614 +}
8615 +
8616  static void
8617  ppc_linux_new_thread (ptid_t ptid)
8618  {
8619 @@ -2349,6 +2367,7 @@ _initialize_ppc_linux_nat (void)
8620    t->to_region_ok_for_hw_watchpoint = ppc_linux_region_ok_for_hw_watchpoint;
8621    t->to_insert_watchpoint = ppc_linux_insert_watchpoint;
8622    t->to_remove_watchpoint = ppc_linux_remove_watchpoint;
8623 +  t->to_detach_watchpoints = ppc_linux_detach_watchpoints;
8624    t->to_stopped_by_watchpoint = ppc_linux_stopped_by_watchpoint;
8625    t->to_stopped_data_address = ppc_linux_stopped_data_address;
8626    t->to_watchpoint_addr_within_range = ppc_linux_watchpoint_addr_within_range;
8627 diff --git a/gdb/printcmd.c b/gdb/printcmd.c
8628 index 5ffa099..58d9c79 100644
8629 --- a/gdb/printcmd.c
8630 +++ b/gdb/printcmd.c
8631 @@ -971,6 +971,11 @@ print_command_1 (char *exp, int inspect, int voidprint)
8632    else
8633      val = access_value_history (0);
8634  
8635 +  /* Do not try to OBJECT_ADDRESS_SET here anything.  We are interested in the
8636 +     source variable base addresses as found by READ_VAR_VALUE.  The value here
8637 +     can be already a calculated expression address inappropriate for
8638 +     DW_OP_push_object_address.  */
8639 +
8640    if (voidprint || (val && value_type (val) &&
8641                     TYPE_CODE (value_type (val)) != TYPE_CODE_VOID))
8642      {
8643 @@ -1471,6 +1476,22 @@ x_command (char *exp, int from_tty)
8644         set_internalvar (lookup_internalvar ("__"), last_examine_value);
8645      }
8646  }
8647 +
8648 +/* Call type_mark_used for any TYPEs referenced from this GDB source file.  */
8649 +
8650 +static void
8651 +print_types_mark_used (void)
8652 +{
8653 +  struct display *d;
8654 +
8655 +  if (last_examine_value)
8656 +    type_mark_used (value_type (last_examine_value));
8657 +
8658 +  for (d = display_chain; d; d = d->next)
8659 +    if (d->exp)
8660 +      exp_types_mark_used (d->exp);
8661 +}
8662 +
8663  \f
8664  
8665  /* Add an expression to the auto-display chain.
8666 @@ -2869,4 +2890,6 @@ Show printing of source filename and line number with <symbol>."), NULL,
8667    add_com ("eval", no_class, eval_command, _("\
8668  Convert \"printf format string\", arg1, arg2, arg3, ..., argn to\n\
8669  a command line, and call it."));
8670 +
8671 +  observer_attach_mark_used (print_types_mark_used);
8672  }
8673 diff --git a/gdb/psymtab.c b/gdb/psymtab.c
8674 index 97a4eec..fce19c9 100644
8675 --- a/gdb/psymtab.c
8676 +++ b/gdb/psymtab.c
8677 @@ -421,6 +421,14 @@ lookup_symbol_aux_psymtabs (struct objfile *objfile,
8678    return NULL;
8679  }
8680  
8681 +static void
8682 +pre_expand_symtabs_matching_psymtabs (struct objfile *objfile,
8683 +                                     int kind, const char *name,
8684 +                                     domain_enum domain)
8685 +{
8686 +  /* Nothing.  */
8687 +}
8688 +
8689  /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
8690     Check the global symbols if GLOBAL, the static symbols if not. */
8691  
8692 @@ -941,7 +949,7 @@ psymtab_to_fullname (struct partial_symtab *ps)
8693    return NULL;
8694  }
8695  
8696 -static char *
8697 +static const char *
8698  find_symbol_file_from_partial (struct objfile *objfile, const char *name)
8699  {
8700    struct partial_symtab *pst;
8701 @@ -1199,6 +1207,7 @@ const struct quick_symbol_functions psym_functions =
8702    forget_cached_source_info_partial,
8703    lookup_symtab_via_partial_symtab,
8704    lookup_symbol_aux_psymtabs,
8705 +  pre_expand_symtabs_matching_psymtabs,
8706    print_psymtab_stats_for_objfile,
8707    dump_psymtabs_for_objfile,
8708    relocate_psymtabs,
8709 diff --git a/gdb/psymtab.h b/gdb/psymtab.h
8710 index 9b8c8df..de8b67e 100644
8711 --- a/gdb/psymtab.h
8712 +++ b/gdb/psymtab.h
8713 @@ -1,6 +1,6 @@
8714  /* Public partial symbol table definitions.
8715  
8716 -   Copyright (C) 2009 Free Software Foundation, Inc.
8717 +   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
8718  
8719     This file is part of GDB.
8720  
8721 @@ -28,4 +28,6 @@ void map_partial_symbol_filenames (void (*) (const char *, const char *,
8722  
8723  extern const struct quick_symbol_functions psym_functions;
8724  
8725 +extern const struct quick_symbol_functions dwarf2_gdb_index_functions;
8726 +
8727  #endif /* PSYMTAB_H */
8728 diff --git a/gdb/python/lib/gdb/FrameIterator.py b/gdb/python/lib/gdb/FrameIterator.py
8729 new file mode 100644
8730 index 0000000..5654546
8731 --- /dev/null
8732 +++ b/gdb/python/lib/gdb/FrameIterator.py
8733 @@ -0,0 +1,33 @@
8734 +# Iterator over frames.
8735 +
8736 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
8737 +
8738 +# This program is free software; you can redistribute it and/or modify
8739 +# it under the terms of the GNU General Public License as published by
8740 +# the Free Software Foundation; either version 3 of the License, or
8741 +# (at your option) any later version.
8742 +#
8743 +# This program is distributed in the hope that it will be useful,
8744 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
8745 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8746 +# GNU General Public License for more details.
8747 +#
8748 +# You should have received a copy of the GNU General Public License
8749 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
8750 +
8751 +class FrameIterator:
8752 +    """An iterator that iterates over frames."""
8753 +
8754 +    def __init__ (self, frame):
8755 +        "Initialize a FrameIterator.  FRAME is the starting frame."
8756 +        self.frame = frame
8757 +
8758 +    def __iter__ (self):
8759 +        return self
8760 +
8761 +    def next (self):
8762 +        result = self.frame
8763 +        if result is None:
8764 +            raise StopIteration
8765 +        self.frame = result.older ()
8766 +        return result
8767 diff --git a/gdb/python/lib/gdb/FrameWrapper.py b/gdb/python/lib/gdb/FrameWrapper.py
8768 new file mode 100644
8769 index 0000000..b790a54
8770 --- /dev/null
8771 +++ b/gdb/python/lib/gdb/FrameWrapper.py
8772 @@ -0,0 +1,112 @@
8773 +# Wrapper API for frames.
8774 +
8775 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
8776 +
8777 +# This program is free software; you can redistribute it and/or modify
8778 +# it under the terms of the GNU General Public License as published by
8779 +# the Free Software Foundation; either version 3 of the License, or
8780 +# (at your option) any later version.
8781 +#
8782 +# This program is distributed in the hope that it will be useful,
8783 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
8784 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8785 +# GNU General Public License for more details.
8786 +#
8787 +# You should have received a copy of the GNU General Public License
8788 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
8789 +
8790 +import gdb
8791 +
8792 +# FIXME: arguably all this should be on Frame somehow.
8793 +class FrameWrapper:
8794 +    def __init__ (self, frame):
8795 +        self.frame = frame;
8796 +
8797 +    def write_symbol (self, stream, sym, block):
8798 +        if len (sym.linkage_name):
8799 +            nsym, is_field_of_this = gdb.lookup_symbol (sym.linkage_name, block)
8800 +            if nsym.addr_class != gdb.SYMBOL_LOC_REGISTER:
8801 +                sym = nsym
8802 +
8803 +        stream.write (sym.print_name + "=")
8804 +        try:
8805 +            val = self.read_var (sym)
8806 +            if val != None:
8807 +                val = str (val)
8808 +        # FIXME: would be nice to have a more precise exception here.
8809 +        except RuntimeError, text:
8810 +            val = text
8811 +        if val == None:
8812 +            stream.write ("???")
8813 +        else:
8814 +            stream.write (str (val))
8815 +
8816 +    def print_frame_locals (self, stream, func):
8817 +        if not func:
8818 +            return
8819 +
8820 +        first = True
8821 +        block = func.value
8822 +
8823 +        for sym in block:
8824 +            if sym.is_argument:
8825 +                continue;
8826 +
8827 +            self.write_symbol (stream, sym, block)
8828 +            stream.write ('\n')
8829 +
8830 +    def print_frame_args (self, stream, func):
8831 +        if not func:
8832 +            return
8833 +
8834 +        first = True
8835 +        block = func.value
8836 +
8837 +        for sym in block:
8838 +            if not sym.is_argument:
8839 +                continue;
8840 +
8841 +            if not first:
8842 +                stream.write (", ")
8843 +
8844 +            self.write_symbol (stream, sym, block)
8845 +            first = False
8846 +
8847 +    # FIXME: this should probably just be a method on gdb.Frame.
8848 +    # But then we need stream wrappers.
8849 +    def describe (self, stream, full):
8850 +        if self.type () == gdb.DUMMY_FRAME:
8851 +            stream.write (" <function called from gdb>\n")
8852 +        elif self.type () == gdb.SIGTRAMP_FRAME:
8853 +            stream.write (" <signal handler called>\n")
8854 +        else:
8855 +            sal = self.find_sal ()
8856 +            pc = self.pc ()
8857 +            name = self.name ()
8858 +            if not name:
8859 +                name = "??"
8860 +            if pc != sal.pc or not sal.symtab:
8861 +                stream.write (" 0x%08x in" % pc)
8862 +            stream.write (" " + name + " (")
8863 +
8864 +            func = self.function ()
8865 +            self.print_frame_args (stream, func)
8866 +
8867 +            stream.write (")")
8868 +
8869 +            if sal.symtab and sal.symtab.filename:
8870 +                stream.write (" at " + sal.symtab.filename)
8871 +                stream.write (":" + str (sal.line))
8872 +
8873 +            if not self.name () or (not sal.symtab or not sal.symtab.filename):
8874 +                lib = gdb.solib_address (pc)
8875 +                if lib:
8876 +                    stream.write (" from " + lib)
8877 +
8878 +            stream.write ("\n")
8879 +
8880 +            if full:
8881 +                self.print_frame_locals (stream, func)
8882 +
8883 +    def __getattr__ (self, name):
8884 +        return getattr (self.frame, name)
8885 diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py
8886 new file mode 100644
8887 index 0000000..b375c68
8888 --- /dev/null
8889 +++ b/gdb/python/lib/gdb/__init__.py
8890 @@ -0,0 +1,19 @@
8891 +# Startup code.
8892 +
8893 +# Copyright (C) 2008 Free Software Foundation, Inc.
8894 +
8895 +# This program is free software; you can redistribute it and/or modify
8896 +# it under the terms of the GNU General Public License as published by
8897 +# the Free Software Foundation; either version 3 of the License, or
8898 +# (at your option) any later version.
8899 +#
8900 +# This program is distributed in the hope that it will be useful,
8901 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
8902 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8903 +# GNU General Public License for more details.
8904 +#
8905 +# You should have received a copy of the GNU General Public License
8906 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
8907 +
8908 +# Load the require command by default.
8909 +import gdb.command.require
8910 diff --git a/gdb/python/lib/gdb/backtrace.py b/gdb/python/lib/gdb/backtrace.py
8911 new file mode 100644
8912 index 0000000..2baab5f
8913 --- /dev/null
8914 +++ b/gdb/python/lib/gdb/backtrace.py
8915 @@ -0,0 +1,42 @@
8916 +# Filtering backtrace.
8917 +
8918 +# Copyright (C) 2008 Free Software Foundation, Inc.
8919 +
8920 +# This program is free software; you can redistribute it and/or modify
8921 +# it under the terms of the GNU General Public License as published by
8922 +# the Free Software Foundation; either version 3 of the License, or
8923 +# (at your option) any later version.
8924 +#
8925 +# This program is distributed in the hope that it will be useful,
8926 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
8927 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8928 +# GNU General Public License for more details.
8929 +#
8930 +# You should have received a copy of the GNU General Public License
8931 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
8932 +
8933 +import gdb
8934 +import itertools
8935 +
8936 +# Our only exports.
8937 +__all__ = ['push_frame_filter', 'create_frame_filter']
8938 +
8939 +frame_filter = None
8940 +
8941 +def push_frame_filter (constructor):
8942 +    """Register a new backtrace filter class with the 'backtrace' command.
8943 +The filter will be passed an iterator as an argument.  The iterator
8944 +will return gdb.Frame-like objects.  The filter should in turn act as
8945 +an iterator returning such objects."""
8946 +    global frame_filter
8947 +    if frame_filter == None:
8948 +        frame_filter = constructor
8949 +    else:
8950 +        frame_filter = lambda iterator: constructor (frame_filter (iterator))
8951 +
8952 +def create_frame_filter (iter):
8953 +    global frame_filter
8954 +    if frame_filter is None:
8955 +        return iter
8956 +    return frame_filter (iter)
8957 +
8958 diff --git a/gdb/python/lib/gdb/command/__init__.py b/gdb/python/lib/gdb/command/__init__.py
8959 new file mode 100644
8960 index 0000000..8b13789
8961 --- /dev/null
8962 +++ b/gdb/python/lib/gdb/command/__init__.py
8963 @@ -0,0 +1 @@
8964 +
8965 diff --git a/gdb/python/lib/gdb/command/alias.py b/gdb/python/lib/gdb/command/alias.py
8966 new file mode 100644
8967 index 0000000..96b6618
8968 --- /dev/null
8969 +++ b/gdb/python/lib/gdb/command/alias.py
8970 @@ -0,0 +1,59 @@
8971 +# Alias command.
8972 +
8973 +# Copyright (C) 2008 Free Software Foundation, Inc.
8974 +
8975 +# This program is free software; you can redistribute it and/or modify
8976 +# it under the terms of the GNU General Public License as published by
8977 +# the Free Software Foundation; either version 3 of the License, or
8978 +# (at your option) any later version.
8979 +#
8980 +# This program is distributed in the hope that it will be useful,
8981 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
8982 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8983 +# GNU General Public License for more details.
8984 +#
8985 +# You should have received a copy of the GNU General Public License
8986 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
8987 +
8988 +import gdb
8989 +
8990 +class AliasImplementation (gdb.Command):
8991 +    def __init__ (self, name, real, doc):
8992 +        # Have to set __doc__ before the super init call.
8993 +        # It would be nice if gdb's help looked up __doc__ dynamically.
8994 +        self.__doc__ = doc
8995 +        # Note: no good way to complete :(
8996 +        super (AliasImplementation, self).__init__ (name, gdb.COMMAND_NONE)
8997 +        self.real = real
8998 +
8999 +    def invoke(self, arg, from_tty):
9000 +        gdb.execute (self.real + ' ' + arg, from_tty)
9001 +
9002 +class AliasCommand (gdb.Command):
9003 +    """Alias one command to another.
9004 +In the simplest form, the first word is the name of the alias, and
9005 +the remaining words are the the expansion.
9006 +An '=' by itself can be used to define a multi-word alias; words
9007 +before the '=' are the name of the new command."""
9008 +
9009 +    def __init__ (self):
9010 +        # Completion is not quite right here.
9011 +        super (AliasCommand, self).__init__ ("alias", gdb.COMMAND_NONE,
9012 +                                             gdb.COMPLETE_COMMAND)
9013 +
9014 +    def invoke (self, arg, from_tty):
9015 +        self.dont_repeat ()
9016 +        # Without some form of quoting we can't alias a multi-word
9017 +        # command to another command.
9018 +        args = arg.split()
9019 +        try:
9020 +            start = args.index ('=')
9021 +            end = start + 1
9022 +        except ValueError:
9023 +            start = 1
9024 +            end = 1
9025 +        target = " ".join(args[end:])
9026 +        AliasImplementation (" ".join (args[0:start]), target,
9027 +                             "This command is an alias for '%s'." % target)
9028 +
9029 +AliasCommand()
9030 diff --git a/gdb/python/lib/gdb/command/backtrace.py b/gdb/python/lib/gdb/command/backtrace.py
9031 new file mode 100644
9032 index 0000000..ec9a527
9033 --- /dev/null
9034 +++ b/gdb/python/lib/gdb/command/backtrace.py
9035 @@ -0,0 +1,106 @@
9036 +# New backtrace command.
9037 +
9038 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
9039 +
9040 +# This program is free software; you can redistribute it and/or modify
9041 +# it under the terms of the GNU General Public License as published by
9042 +# the Free Software Foundation; either version 3 of the License, or
9043 +# (at your option) any later version.
9044 +#
9045 +# This program is distributed in the hope that it will be useful,
9046 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
9047 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9048 +# GNU General Public License for more details.
9049 +#
9050 +# You should have received a copy of the GNU General Public License
9051 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
9052 +
9053 +import gdb
9054 +import gdb.backtrace
9055 +import itertools
9056 +from gdb.FrameIterator import FrameIterator
9057 +from gdb.FrameWrapper import FrameWrapper
9058 +import sys
9059 +
9060 +class ReverseBacktraceParameter (gdb.Parameter):
9061 +    """The new-backtrace command can show backtraces in 'reverse' order.
9062 +This means that the innermost frame will be printed last.
9063 +Note that reverse backtraces are more expensive to compute."""
9064 +
9065 +    set_doc = "Enable or disable reverse backtraces."
9066 +    show_doc = "Show whether backtraces will be printed in reverse order."
9067 +
9068 +    def __init__(self):
9069 +        gdb.Parameter.__init__ (self, "reverse-backtrace",
9070 +                                gdb.COMMAND_STACK, gdb.PARAM_BOOLEAN)
9071 +        # Default to compatibility with gdb.
9072 +        self.value = False
9073 +
9074 +class FilteringBacktrace (gdb.Command):
9075 +    """Print backtrace of all stack frames, or innermost COUNT frames.
9076 +With a negative argument, print outermost -COUNT frames.
9077 +Use of the 'full' qualifier also prints the values of the local variables.
9078 +Use of the 'raw' qualifier avoids any filtering by loadable modules.
9079 +"""
9080 +
9081 +    def __init__ (self):
9082 +        # FIXME: this is not working quite well enough to replace
9083 +        # "backtrace" yet.
9084 +        gdb.Command.__init__ (self, "new-backtrace", gdb.COMMAND_STACK)
9085 +        self.reverse = ReverseBacktraceParameter()
9086 +
9087 +    def reverse_iter (self, iter):
9088 +        result = []
9089 +        for item in iter:
9090 +            result.append (item)
9091 +        result.reverse()
9092 +        return result
9093 +
9094 +    def final_n (self, iter, x):
9095 +        result = []
9096 +        for item in iter:
9097 +            result.append (item)
9098 +        return result[x:]
9099 +
9100 +    def invoke (self, arg, from_tty):
9101 +        i = 0
9102 +        count = 0
9103 +        filter = True
9104 +        full = False
9105 +
9106 +        for word in arg.split (" "):
9107 +            if word == '':
9108 +                continue
9109 +            elif word == 'raw':
9110 +                filter = False
9111 +            elif word == 'full':
9112 +                full = True
9113 +            else:
9114 +                count = int (word)
9115 +
9116 +        # FIXME: provide option to start at selected frame
9117 +        # However, should still number as if starting from newest
9118 +       newest_frame = gdb.selected_thread ().newest_frame ()
9119 +        iter = itertools.imap (FrameWrapper,
9120 +                               FrameIterator (newest_frame))
9121 +        if filter:
9122 +            iter = gdb.backtrace.create_frame_filter (iter)
9123 +
9124 +        # Now wrap in an iterator that numbers the frames.
9125 +        iter = itertools.izip (itertools.count (0), iter)
9126 +
9127 +        # Reverse if the user wanted that.
9128 +        if self.reverse.value:
9129 +            iter = self.reverse_iter (iter)
9130 +
9131 +        # Extract sub-range user wants.
9132 +        if count < 0:
9133 +            iter = self.final_n (iter, count)
9134 +        elif count > 0:
9135 +            iter = itertools.islice (iter, 0, count)
9136 +
9137 +        for pair in iter:
9138 +            sys.stdout.write ("#%-2d" % pair[0])
9139 +            pair[1].describe (sys.stdout, full)
9140 +
9141 +FilteringBacktrace()
9142 diff --git a/gdb/python/lib/gdb/command/ignore_errors.py b/gdb/python/lib/gdb/command/ignore_errors.py
9143 new file mode 100644
9144 index 0000000..6fa48ff
9145 --- /dev/null
9146 +++ b/gdb/python/lib/gdb/command/ignore_errors.py
9147 @@ -0,0 +1,37 @@
9148 +# Ignore errors in user commands.
9149 +
9150 +# Copyright (C) 2008 Free Software Foundation, Inc.
9151 +
9152 +# This program is free software; you can redistribute it and/or modify
9153 +# it under the terms of the GNU General Public License as published by
9154 +# the Free Software Foundation; either version 3 of the License, or
9155 +# (at your option) any later version.
9156 +#
9157 +# This program is distributed in the hope that it will be useful,
9158 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
9159 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9160 +# GNU General Public License for more details.
9161 +#
9162 +# You should have received a copy of the GNU General Public License
9163 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
9164 +
9165 +import gdb
9166 +
9167 +class IgnoreErrorsCommand (gdb.Command):
9168 +    """Execute a single command, ignoring all errors.
9169 +Only one-line commands are supported.
9170 +This is primarily useful in scripts."""
9171 +
9172 +    def __init__ (self):
9173 +        super (IgnoreErrorsCommand, self).__init__ ("ignore-errors",
9174 +                                                    gdb.COMMAND_OBSCURE,
9175 +                                                    # FIXME...
9176 +                                                    gdb.COMPLETE_COMMAND)
9177 +
9178 +    def invoke (self, arg, from_tty):
9179 +        try:
9180 +            gdb.execute (arg, from_tty)
9181 +        except:
9182 +            pass
9183 +
9184 +IgnoreErrorsCommand ()
9185 diff --git a/gdb/python/lib/gdb/command/pahole.py b/gdb/python/lib/gdb/command/pahole.py
9186 new file mode 100644
9187 index 0000000..21a0bf0
9188 --- /dev/null
9189 +++ b/gdb/python/lib/gdb/command/pahole.py
9190 @@ -0,0 +1,75 @@
9191 +# pahole command for gdb
9192 +
9193 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
9194 +
9195 +# This program is free software; you can redistribute it and/or modify
9196 +# it under the terms of the GNU General Public License as published by
9197 +# the Free Software Foundation; either version 3 of the License, or
9198 +# (at your option) any later version.
9199 +#
9200 +# This program is distributed in the hope that it will be useful,
9201 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
9202 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9203 +# GNU General Public License for more details.
9204 +#
9205 +# You should have received a copy of the GNU General Public License
9206 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
9207 +
9208 +import gdb
9209 +
9210 +class Pahole (gdb.Command):
9211 +    """Show the holes in a structure.
9212 +This command takes a single argument, a type name.
9213 +It prints the type and displays comments showing where holes are."""
9214 +
9215 +    def __init__ (self):
9216 +        super (Pahole, self).__init__ ("pahole", gdb.COMMAND_NONE,
9217 +                                       gdb.COMPLETE_SYMBOL)
9218 +
9219 +    def pahole (self, type, level, name):
9220 +        if name is None:
9221 +            name = ''
9222 +        tag = type.tag
9223 +        if tag is None:
9224 +            tag = ''
9225 +        print '%sstruct %s {' % (' ' * (2 * level), tag)
9226 +        bitpos = 0
9227 +        for field in type.fields ():
9228 +            # Skip static fields.
9229 +            if not hasattr (field, ('bitpos')):
9230 +                continue
9231 +
9232 +            ftype = field.type.strip_typedefs()
9233 +
9234 +            if bitpos != field.bitpos:
9235 +                hole = field.bitpos - bitpos
9236 +                print '  /* XXX %d bit hole, try to pack */' % hole
9237 +                bitpos = field.bitpos
9238 +            if field.bitsize > 0:
9239 +                fieldsize = field.bitsize
9240 +            else:
9241 +                # TARGET_CHAR_BIT here...
9242 +                fieldsize = 8 * ftype.sizeof
9243 +
9244 +            # TARGET_CHAR_BIT
9245 +            print ' /* %3d %3d */' % (int (bitpos / 8), int (fieldsize / 8)),
9246 +            bitpos = bitpos + fieldsize
9247 +
9248 +            if ftype.code == gdb.TYPE_CODE_STRUCT:
9249 +                self.pahole (ftype, level + 1, field.name)
9250 +            else:
9251 +                print ' ' * (2 + 2 * level),
9252 +                print '%s %s' % (str (ftype), field.name)
9253 +
9254 +        print ' ' * (14 + 2 * level),
9255 +        print '} %s' % name
9256 +
9257 +    def invoke (self, arg, from_tty):
9258 +        type = gdb.lookup_type (arg)
9259 +        type = type.strip_typedefs ()
9260 +        if type.code != gdb.TYPE_CODE_STRUCT:
9261 +            raise TypeError, '%s is not a struct type' % arg
9262 +        print ' ' * 14,
9263 +        self.pahole (type, 0, '')
9264 +
9265 +Pahole()
9266 diff --git a/gdb/python/lib/gdb/command/require.py b/gdb/python/lib/gdb/command/require.py
9267 new file mode 100644
9268 index 0000000..1fbc1e8
9269 --- /dev/null
9270 +++ b/gdb/python/lib/gdb/command/require.py
9271 @@ -0,0 +1,57 @@
9272 +# Demand-loading commands.
9273 +
9274 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
9275 +
9276 +# This program is free software; you can redistribute it and/or modify
9277 +# it under the terms of the GNU General Public License as published by
9278 +# the Free Software Foundation; either version 3 of the License, or
9279 +# (at your option) any later version.
9280 +#
9281 +# This program is distributed in the hope that it will be useful,
9282 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
9283 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9284 +# GNU General Public License for more details.
9285 +#
9286 +# You should have received a copy of the GNU General Public License
9287 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
9288 +
9289 +import gdb
9290 +import os
9291 +
9292 +class RequireCommand (gdb.Command):
9293 +    """Prefix command for requiring features."""
9294 +
9295 +    def __init__ (self):
9296 +        super (RequireCommand, self).__init__ ("require",
9297 +                                               gdb.COMMAND_SUPPORT,
9298 +                                               gdb.COMPLETE_NONE,
9299 +                                               True)
9300 +
9301 +class RequireSubcommand (gdb.Command):
9302 +    """Demand-load a command by name."""
9303 +
9304 +    def __init__ (self, name):
9305 +        self.__doc__ = "Demand-load a %s by name." % name
9306 +        super (RequireSubcommand, self).__init__ ("require %s" % name,
9307 +                                                  gdb.COMMAND_SUPPORT)
9308 +        self.name = name
9309 +
9310 +    def invoke (self, arg, from_tty):
9311 +        for cmd in arg.split():
9312 +            exec ('import gdb.' + self.name + '.' + cmd, globals ())
9313 +
9314 +    def complete (self, text, word):
9315 +        dir = gdb.pythondir + '/gdb/' + self.name
9316 +        result = []
9317 +        for file in os.listdir(dir):
9318 +            if not file.startswith (word) or not file.endswith ('.py'):
9319 +                continue
9320 +            feature = file[0:-3]
9321 +            if feature == 'require' or feature == '__init__':
9322 +                continue
9323 +            result.append (feature)
9324 +        return result
9325 +
9326 +RequireCommand()
9327 +RequireSubcommand("command")
9328 +RequireSubcommand("function")
9329 diff --git a/gdb/python/lib/gdb/command/save_breakpoints.py b/gdb/python/lib/gdb/command/save_breakpoints.py
9330 new file mode 100644
9331 index 0000000..6143187
9332 --- /dev/null
9333 +++ b/gdb/python/lib/gdb/command/save_breakpoints.py
9334 @@ -0,0 +1,65 @@
9335 +# Save breakpoints.
9336 +
9337 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
9338 +
9339 +# This program is free software; you can redistribute it and/or modify
9340 +# it under the terms of the GNU General Public License as published by
9341 +# the Free Software Foundation; either version 3 of the License, or
9342 +# (at your option) any later version.
9343 +#
9344 +# This program is distributed in the hope that it will be useful,
9345 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
9346 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9347 +# GNU General Public License for more details.
9348 +#
9349 +# You should have received a copy of the GNU General Public License
9350 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
9351 +
9352 +from __future__ import with_statement
9353 +import gdb
9354 +
9355 +class SavePrefixCommand (gdb.Command):
9356 +  "Prefix command for saving things."
9357 +
9358 +  def __init__ (self):
9359 +    super (SavePrefixCommand, self).__init__ ("save",
9360 +                                              gdb.COMMAND_SUPPORT,
9361 +                                              gdb.COMPLETE_NONE, True)
9362 +
9363 +class SaveBreakpointsCommand (gdb.Command):
9364 +    """Save the current breakpoints to a file.
9365 +This command takes a single argument, a file name.
9366 +The breakpoints can be restored using the 'source' command."""
9367 +
9368 +    def __init__ (self):
9369 +        super (SaveBreakpointsCommand, self).__init__ ("save breakpoints",
9370 +                                                       gdb.COMMAND_SUPPORT,
9371 +                                                       gdb.COMPLETE_FILENAME)
9372 +
9373 +    def invoke (self, arg, from_tty):
9374 +        self.dont_repeat ()
9375 +        bps = gdb.breakpoints ()
9376 +        if bps is None:
9377 +            raise RuntimeError, 'No breakpoints to save'
9378 +        with open (arg.strip (), 'w') as f:
9379 +            for bp in bps:
9380 +                print >> f, "break", bp.location,
9381 +                if bp.thread is not None:
9382 +                    print >> f, " thread", bp.thread,
9383 +                if bp.condition is not None:
9384 +                    print >> f, " if", bp.condition,
9385 +                print >> f
9386 +                if not bp.enabled:
9387 +                    print >> f, "disable $bpnum"
9388 +                # Note: we don't save the ignore count; there doesn't
9389 +                # seem to be much point.
9390 +                commands = bp.commands
9391 +                if commands is not None:
9392 +                    print >> f, "commands"
9393 +                    # Note that COMMANDS has a trailing newline.
9394 +                    print >> f, commands,
9395 +                    print >> f, "end"
9396 +                print >> f
9397 +
9398 +SavePrefixCommand ()
9399 +SaveBreakpointsCommand ()
9400 diff --git a/gdb/python/lib/gdb/command/upto.py b/gdb/python/lib/gdb/command/upto.py
9401 new file mode 100644
9402 index 0000000..faf54ed
9403 --- /dev/null
9404 +++ b/gdb/python/lib/gdb/command/upto.py
9405 @@ -0,0 +1,129 @@
9406 +# upto command.
9407 +
9408 +# Copyright (C) 2009 Free Software Foundation, Inc.
9409 +
9410 +# This program is free software; you can redistribute it and/or modify
9411 +# it under the terms of the GNU General Public License as published by
9412 +# the Free Software Foundation; either version 3 of the License, or
9413 +# (at your option) any later version.
9414 +#
9415 +# This program is distributed in the hope that it will be useful,
9416 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
9417 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9418 +# GNU General Public License for more details.
9419 +#
9420 +# You should have received a copy of the GNU General Public License
9421 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
9422 +
9423 +import gdb
9424 +import re
9425 +from gdb.FrameIterator import FrameIterator
9426 +from gdb.FrameWrapper import FrameWrapper
9427 +
9428 +class UptoPrefix (gdb.Command):
9429 +    def __init__ (self):
9430 +        super (UptoPrefix, self).__init__ ("upto", gdb.COMMAND_STACK,
9431 +                                           prefix = True)
9432 +
9433 +class UptoImplementation (gdb.Command):
9434 +    def __init__ (self, subcommand):
9435 +        super (UptoImplementation, self).__init__ ("upto " + subcommand,
9436 +                                                   gdb.COMMAND_STACK)
9437 +
9438 +    def search (self):
9439 +        saved = gdb.selected_frame ()
9440 +        iter = FrameIterator (saved)
9441 +        found = False
9442 +        try:
9443 +            for frame in iter:
9444 +                frame.select ()
9445 +                try:
9446 +                    if self.filter (frame):
9447 +                        wrapper = FrameWrapper (frame)
9448 +                        wrapper.describe (sys.stdout, False)
9449 +                        return
9450 +                except:
9451 +                    pass
9452 +        except:
9453 +            pass
9454 +        saved.select ()
9455 +        raise RuntimeError, 'Could not find a matching frame'
9456 +
9457 +    def invoke (self, arg, from_tty):
9458 +        self.rx = re.compile (arg)
9459 +        self.search ()
9460 +
9461 +class UptoSymbolCommand (UptoImplementation):
9462 +    """Select and print some calling stack frame, based on symbol.
9463 +The argument is a regular expression.  This command moves up the
9464 +stack, stopping at the first frame whose symbol matches the regular
9465 +expression."""
9466 +
9467 +    def __init__ (self):
9468 +        super (UptoSymbolCommand, self).__init__ ("symbol")
9469 +
9470 +    def filter (self, frame):
9471 +        name = frame.name ()
9472 +        if name is not None:
9473 +            if self.rx.search (name) is not None:
9474 +                return True
9475 +        return False
9476 +
9477 +class UptoSourceCommand (UptoImplementation):
9478 +    """Select and print some calling stack frame, based on source file.
9479 +The argument is a regular expression.  This command moves up the
9480 +stack, stopping at the first frame whose source file name matches the
9481 +regular expression."""
9482 +
9483 +    def __init__ (self):
9484 +        super (UptoSourceCommand, self).__init__ ("source")
9485 +
9486 +    def filter (self, frame):
9487 +        name = frame.find_sal ().symtab.filename
9488 +        if name is not None:
9489 +            if self.rx.search (name) is not None:
9490 +                return True
9491 +        return False
9492 +
9493 +class UptoObjectCommand (UptoImplementation):
9494 +    """Select and print some calling stack frame, based on object file.
9495 +The argument is a regular expression.  This command moves up the
9496 +stack, stopping at the first frame whose object file name matches the
9497 +regular expression."""
9498 +
9499 +    def __init__ (self):
9500 +        super (UptoObjectCommand, self).__init__ ("object")
9501 +
9502 +    def filter (self, frame):
9503 +        name = frame.find_sal ().symtab.objfile.filename
9504 +        if name is not None:
9505 +            if self.rx.search (name) is not None:
9506 +                return True
9507 +        return False
9508 +
9509 +class UptoWhereCommand (UptoImplementation):
9510 +    """Select and print some calling stack frame, based on expression.
9511 +The argument is an expression.  This command moves up the stack,
9512 +parsing and evaluating the expression in each frame.  This stops when
9513 +the expression evaluates to a non-zero (true) value."""
9514 +
9515 +    def __init__ (self):
9516 +        super (UptoWhereCommand, self).__init__ ("where")
9517 +
9518 +    def filter (self, frame):
9519 +        try:
9520 +            if gdb.parse_and_eval (self.expression):
9521 +                return True
9522 +        except:
9523 +            pass
9524 +        return False
9525 +
9526 +    def invoke (self, arg, from_tty):
9527 +        self.expression = arg
9528 +        self.search ()
9529 +
9530 +UptoPrefix ()
9531 +UptoSymbolCommand ()
9532 +UptoSourceCommand ()
9533 +UptoObjectCommand ()
9534 +UptoWhereCommand ()
9535 diff --git a/gdb/python/lib/gdb/function/__init__.py b/gdb/python/lib/gdb/function/__init__.py
9536 new file mode 100644
9537 index 0000000..8b13789
9538 --- /dev/null
9539 +++ b/gdb/python/lib/gdb/function/__init__.py
9540 @@ -0,0 +1 @@
9541 +
9542 diff --git a/gdb/python/lib/gdb/function/caller_is.py b/gdb/python/lib/gdb/function/caller_is.py
9543 new file mode 100644
9544 index 0000000..2b9c5c7
9545 --- /dev/null
9546 +++ b/gdb/python/lib/gdb/function/caller_is.py
9547 @@ -0,0 +1,58 @@
9548 +# Caller-is functions.
9549 +
9550 +# Copyright (C) 2008 Free Software Foundation, Inc.
9551 +
9552 +# This program is free software; you can redistribute it and/or modify
9553 +# it under the terms of the GNU General Public License as published by
9554 +# the Free Software Foundation; either version 3 of the License, or
9555 +# (at your option) any later version.
9556 +#
9557 +# This program is distributed in the hope that it will be useful,
9558 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
9559 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9560 +# GNU General Public License for more details.
9561 +#
9562 +# You should have received a copy of the GNU General Public License
9563 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
9564 +
9565 +import gdb
9566 +import re
9567 +
9568 +class CallerIs (gdb.Function):
9569 +    """Return True if the calling function's name is equal to a string.
9570 +This function takes one or two arguments.
9571 +The first argument is the name of a function; if the calling function's
9572 +name is equal to this argument, this function returns True.
9573 +The optional second argument tells this function how many stack frames
9574 +to traverse to find the calling function.  The default is 1."""
9575 +
9576 +    def __init__ (self):
9577 +        super (CallerIs, self).__init__ ("caller_is")
9578 +
9579 +    def invoke (self, name, nframes = 1):
9580 +        frame = gdb.selected_frame ()
9581 +        while nframes > 0:
9582 +            frame = frame.older ()
9583 +            nframes = nframes - 1
9584 +        return frame.name () == name.string ()
9585 +
9586 +class CallerMatches (gdb.Function):
9587 +    """Return True if the calling function's name matches a string.
9588 +This function takes one or two arguments.
9589 +The first argument is a regular expression; if the calling function's
9590 +name is matched by this argument, this function returns True.
9591 +The optional second argument tells this function how many stack frames
9592 +to traverse to find the calling function.  The default is 1."""
9593 +
9594 +    def __init__ (self):
9595 +        super (CallerMatches, self).__init__ ("caller_matches")
9596 +
9597 +    def invoke (self, name, nframes = 1):
9598 +        frame = gdb.selected_frame ()
9599 +        while nframes > 0:
9600 +            frame = frame.older ()
9601 +            nframes = nframes - 1
9602 +        return re.match (name.string (), frame.name ()) is not None
9603 +
9604 +CallerIs()
9605 +CallerMatches()
9606 diff --git a/gdb/python/lib/gdb/function/in_scope.py b/gdb/python/lib/gdb/function/in_scope.py
9607 new file mode 100644
9608 index 0000000..debb3bb
9609 --- /dev/null
9610 +++ b/gdb/python/lib/gdb/function/in_scope.py
9611 @@ -0,0 +1,47 @@
9612 +# In-scope function.
9613 +
9614 +# Copyright (C) 2008 Free Software Foundation, Inc.
9615 +
9616 +# This program is free software; you can redistribute it and/or modify
9617 +# it under the terms of the GNU General Public License as published by
9618 +# the Free Software Foundation; either version 3 of the License, or
9619 +# (at your option) any later version.
9620 +#
9621 +# This program is distributed in the hope that it will be useful,
9622 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
9623 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9624 +# GNU General Public License for more details.
9625 +#
9626 +# You should have received a copy of the GNU General Public License
9627 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
9628 +
9629 +import gdb
9630 +
9631 +class InScope (gdb.Function):
9632 +    """Return True if all the given variables or macros are in scope.
9633 +Takes one argument for each variable name to be checked."""
9634 +
9635 +    def __init__ (self):
9636 +       super (InScope, self).__init__ ("in_scope")
9637 +
9638 +    def invoke (self, *vars):
9639 +        if len (vars) == 0:
9640 +           raise TypeError, "in_scope takes at least one argument"
9641 +
9642 +        # gdb.Value isn't hashable so it can't be put in a map.
9643 +       # Convert to string first.
9644 +       wanted = set (map (lambda x: x.string (), vars))
9645 +       found = set ()
9646 +       block = gdb.selected_frame ().block ()
9647 +       while block:
9648 +           for sym in block:
9649 +               if (sym.is_argument or sym.is_constant
9650 +                     or sym.is_function or sym.is_variable):
9651 +                   if sym.name in wanted:
9652 +                       found.add (sym.name)
9653 +
9654 +           block = block.superblock
9655 +
9656 +       return wanted == found
9657 +
9658 +InScope ()
9659 diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
9660 index 2cff4ba..9255336 100644
9661 --- a/gdb/python/py-cmd.c
9662 +++ b/gdb/python/py-cmd.c
9663 @@ -49,8 +49,7 @@ static struct cmdpy_completer completers[] =
9664  
9665  #define N_COMPLETERS (sizeof (completers) / sizeof (completers[0]))
9666  
9667 -/* A gdb command.  For the time being only ordinary commands (not
9668 -   set/show commands) are allowed.  */
9669 +/* A gdb command.  */
9670  struct cmdpy_object
9671  {
9672    PyObject_HEAD
9673 diff --git a/gdb/python/py-hooks.c b/gdb/python/py-hooks.c
9674 new file mode 100644
9675 index 0000000..a3140bc
9676 --- /dev/null
9677 +++ b/gdb/python/py-hooks.c
9678 @@ -0,0 +1,50 @@
9679 +/* Notifications from gdb to Python
9680 +
9681 +   Copyright (C) 2008 Free Software Foundation, Inc.
9682 +
9683 +   This file is part of GDB.
9684 +
9685 +   This program is free software; you can redistribute it and/or modify
9686 +   it under the terms of the GNU General Public License as published by
9687 +   the Free Software Foundation; either version 3 of the License, or
9688 +   (at your option) any later version.
9689 +
9690 +   This program is distributed in the hope that it will be useful,
9691 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
9692 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9693 +   GNU General Public License for more details.
9694 +
9695 +   You should have received a copy of the GNU General Public License
9696 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
9697 +
9698 +#include "defs.h"
9699 +#include "cli/cli-decode.h"
9700 +#include "charset.h"
9701 +#include "python.h"
9702 +#include "python-internal.h"
9703 +#include "observer.h"
9704 +
9705 +PyObject *
9706 +gdbpy_get_hook_function (const char *name)
9707 +{
9708 +  PyObject *hooks;
9709 +  PyObject *result;
9710 +
9711 +  if (! PyObject_HasAttrString (gdb_module, "hooks"))
9712 +    return NULL;
9713 +  hooks = PyObject_GetAttrString (gdb_module, "hooks");
9714 +  if (! hooks)
9715 +    return NULL;
9716 +  /* The cast is because the Python function doesn't declare const argument.
9717 +     This is a problem in Python version 2.4, but not in 2.5.  */
9718 +  if (! PyObject_HasAttrString (hooks, (char *) name))
9719 +    {
9720 +      Py_DECREF (hooks);
9721 +      return NULL;
9722 +    }
9723 +  /* The cast is because the Python function doesn't declare const argument.
9724 +     This is a problem in Python version 2.4, but not in 2.5.  */
9725 +  result = PyObject_GetAttrString (hooks, (char *) name);
9726 +  Py_DECREF (hooks);
9727 +  return result;
9728 +}
9729 diff --git a/gdb/python/py-membuf.c b/gdb/python/py-membuf.c
9730 new file mode 100644
9731 index 0000000..7bc294c
9732 --- /dev/null
9733 +++ b/gdb/python/py-membuf.c
9734 @@ -0,0 +1,268 @@
9735 +/* Python interface to the inferior memory.
9736 +
9737 +   Copyright (C) 2008, 2009 Free Software Foundation, Inc.
9738 +
9739 +   This file is part of GDB.
9740 +
9741 +   This program is free software; you can redistribute it and/or modify
9742 +   it under the terms of the GNU General Public License as published by
9743 +   the Free Software Foundation; either version 3 of the License, or
9744 +   (at your option) any later version.
9745 +
9746 +   This program is distributed in the hope that it will be useful,
9747 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
9748 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9749 +   GNU General Public License for more details.
9750 +
9751 +   You should have received a copy of the GNU General Public License
9752 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
9753 +
9754 +#include "defs.h"
9755 +#include "exceptions.h"
9756 +#include "gdbcore.h"
9757 +#include "python-internal.h"
9758 +
9759 +typedef struct {
9760 +  PyObject_HEAD
9761 +  void *buffer;
9762 +
9763 +  /* These are kept just for mbpy_str.  */
9764 +  CORE_ADDR addr;
9765 +  CORE_ADDR length;
9766 +} membuf_object;
9767 +
9768 +static PyTypeObject membuf_object_type;
9769 +
9770 +/* Implementation of gdb.read_memory (address, length).
9771 +   Returns a Python buffer object with LENGTH bytes of the inferior's memory
9772 +   at ADDRESS. Both arguments are integers.  */
9773 +
9774 +PyObject *
9775 +gdbpy_read_memory (PyObject *self, PyObject *args)
9776 +{
9777 +  int error = 0;
9778 +  CORE_ADDR addr, length;
9779 +  void *buffer = NULL;
9780 +  membuf_object *membuf_obj;
9781 +  PyObject *addr_obj, *length_obj;
9782 +  struct cleanup *cleanups = NULL;
9783 +  volatile struct gdb_exception except;
9784 +
9785 +  if (! PyArg_ParseTuple (args, "OO", &addr_obj, &length_obj))
9786 +    return NULL;
9787 +
9788 +  TRY_CATCH (except, RETURN_MASK_ALL)
9789 +    {
9790 +      if (!get_addr_from_python (addr_obj, &addr)
9791 +         || !get_addr_from_python (length_obj, &length))
9792 +       {
9793 +         error = 1;
9794 +         break;
9795 +       }
9796 +
9797 +      buffer = xmalloc (length);
9798 +      cleanups = make_cleanup (xfree, buffer);
9799 +
9800 +      read_memory (addr, buffer, length);
9801 +    }
9802 +  GDB_PY_HANDLE_EXCEPTION (except);
9803 +
9804 +  if (error)
9805 +    return NULL;
9806 +
9807 +  discard_cleanups (cleanups);
9808 +
9809 +  membuf_obj = PyObject_New (membuf_object, &membuf_object_type);
9810 +  if (membuf_obj == NULL)
9811 +    {
9812 +      xfree (buffer);
9813 +      PyErr_SetString (PyExc_MemoryError,
9814 +                      "Could not allocate memory buffer object.");
9815 +      return NULL;
9816 +    }
9817 +
9818 +  membuf_obj->buffer = buffer;
9819 +  membuf_obj->addr = addr;
9820 +  membuf_obj->length = length;
9821 +
9822 +  return PyBuffer_FromReadWriteObject ((PyObject *) membuf_obj, 0,
9823 +                                      Py_END_OF_BUFFER);
9824 +}
9825 +
9826 +/* Implementation of gdb.write_memory (address, buffer [, length]).
9827 +   Writes the contents of BUFFER (a Python object supporting the read buffer
9828 +   protocol) at ADDRESS in the inferior's memory.  Write LENGTH bytes from
9829 +   BUFFER, or its entire contents if the argument is not provided.  The
9830 +   function returns nothing.  */
9831 +
9832 +PyObject *
9833 +gdbpy_write_memory (PyObject *self, PyObject *args)
9834 +{
9835 +  int buf_len, error = 0;
9836 +  const char *buffer;
9837 +  CORE_ADDR addr, length;
9838 +  PyObject *addr_obj, *length_obj = NULL;
9839 +  volatile struct gdb_exception except;
9840 +
9841 +  if (! PyArg_ParseTuple (args, "Os#|O", &addr_obj, &buffer, &buf_len,
9842 +                         &length_obj))
9843 +    return NULL;
9844 +
9845 +  TRY_CATCH (except, RETURN_MASK_ALL)
9846 +    {
9847 +      if (!get_addr_from_python (addr_obj, &addr))
9848 +       {
9849 +         error = 1;
9850 +         break;
9851 +       }
9852 +      
9853 +      if (!length_obj)
9854 +       length = buf_len;
9855 +      else if (!get_addr_from_python (length_obj, &length))
9856 +       {
9857 +         error = 1;
9858 +         break;
9859 +       }
9860 +
9861 +      write_memory (addr, buffer, length);
9862 +    }
9863 +  GDB_PY_HANDLE_EXCEPTION (except);
9864 +
9865 +  if (error)
9866 +    return NULL;
9867 +
9868 +  Py_RETURN_NONE;
9869 +}
9870 +
9871 +/* Destructor of Membuf objects.  */
9872 +
9873 +static void
9874 +mbpy_dealloc (PyObject *self)
9875 +{
9876 +  xfree (((membuf_object *) self)->buffer);
9877 +  self->ob_type->tp_free (self);
9878 +}
9879 +
9880 +/* Return a description of the Membuf object.  */
9881 +
9882 +static PyObject *
9883 +mbpy_str (PyObject *self)
9884 +{
9885 +  membuf_object *membuf_obj = (membuf_object *) self;
9886 +
9887 +  return PyString_FromFormat ("memory buffer for address %s, %s bytes long",
9888 +                             paddress (membuf_obj->addr),
9889 +                             pulongest (membuf_obj->length));
9890 +}
9891 +
9892 +static Py_ssize_t
9893 +get_read_buffer (PyObject *self, Py_ssize_t segment, void **ptrptr)
9894 +{
9895 +  membuf_object *membuf_obj = (membuf_object *) self;
9896 +
9897 +  if (segment)
9898 +    {
9899 +      PyErr_SetString (PyExc_SystemError,
9900 +                      "The memory buffer supports only one segment.");
9901 +      return -1;
9902 +    }
9903 +
9904 +  *ptrptr = membuf_obj->buffer;
9905 +
9906 +  return membuf_obj->length;
9907 +}
9908 +
9909 +static Py_ssize_t
9910 +get_write_buffer (PyObject *self, Py_ssize_t segment, void **ptrptr)
9911 +{
9912 +  return get_read_buffer (self, segment, ptrptr);
9913 +}
9914 +
9915 +static Py_ssize_t
9916 +get_seg_count (PyObject *self, Py_ssize_t *lenp)
9917 +{
9918 +  if (lenp)
9919 +    *lenp = ((membuf_object *) self)->length;
9920 +
9921 +  return 1;
9922 +}
9923 +
9924 +static Py_ssize_t
9925 +get_char_buffer (PyObject *self, Py_ssize_t segment, char **ptrptr)
9926 +{
9927 +  void *ptr = NULL;
9928 +  Py_ssize_t ret;
9929 +
9930 +  ret = get_read_buffer (self, segment, &ptr);
9931 +  *ptrptr = (char *) ptr;
9932 +
9933 +  return ret;
9934 +}
9935 +
9936 +/* Python doesn't provide a decent way to get compatibility here.  */
9937 +#if HAVE_LIBPYTHON2_4
9938 +#define CHARBUFFERPROC_NAME getcharbufferproc
9939 +#else
9940 +#define CHARBUFFERPROC_NAME charbufferproc
9941 +#endif
9942 +
9943 +static PyBufferProcs buffer_procs = {
9944 +  get_read_buffer,
9945 +  get_write_buffer,
9946 +  get_seg_count,
9947 +  /* The cast here works around a difference between Python 2.4 and
9948 +     Python 2.5.  */
9949 +  (CHARBUFFERPROC_NAME) get_char_buffer
9950 +};
9951 +
9952 +static PyTypeObject membuf_object_type = {
9953 +  PyObject_HEAD_INIT (NULL)
9954 +  0,                             /*ob_size*/
9955 +  "gdb.Membuf",                          /*tp_name*/
9956 +  sizeof (membuf_object),        /*tp_basicsize*/
9957 +  0,                             /*tp_itemsize*/
9958 +  mbpy_dealloc,                          /*tp_dealloc*/
9959 +  0,                             /*tp_print*/
9960 +  0,                             /*tp_getattr*/
9961 +  0,                             /*tp_setattr*/
9962 +  0,                             /*tp_compare*/
9963 +  0,                             /*tp_repr*/
9964 +  0,                             /*tp_as_number*/
9965 +  0,                             /*tp_as_sequence*/
9966 +  0,                             /*tp_as_mapping*/
9967 +  0,                             /*tp_hash */
9968 +  0,                             /*tp_call*/
9969 +  mbpy_str,                      /*tp_str*/
9970 +  0,                             /*tp_getattro*/
9971 +  0,                             /*tp_setattro*/
9972 +  &buffer_procs,                 /*tp_as_buffer*/
9973 +  Py_TPFLAGS_DEFAULT,            /*tp_flags*/
9974 +  "GDB memory buffer object",    /*tp_doc*/
9975 +  0,                             /* tp_traverse */
9976 +  0,                             /* tp_clear */
9977 +  0,                             /* tp_richcompare */
9978 +  0,                             /* tp_weaklistoffset */
9979 +  0,                             /* tp_iter */
9980 +  0,                             /* tp_iternext */
9981 +  0,                             /* tp_methods */
9982 +  0,                             /* tp_members */
9983 +  0,                             /* tp_getset */
9984 +  0,                             /* tp_base */
9985 +  0,                             /* tp_dict */
9986 +  0,                             /* tp_descr_get */
9987 +  0,                             /* tp_descr_set */
9988 +  0,                             /* tp_dictoffset */
9989 +  0,                             /* tp_init */
9990 +  0,                             /* tp_alloc */
9991 +  PyType_GenericNew              /* tp_new */
9992 +};
9993 +
9994 +void
9995 +gdbpy_initialize_membuf (void)
9996 +{
9997 +  if (PyType_Ready (&membuf_object_type) < 0)
9998 +    return;
9999 +
10000 +  Py_INCREF (&membuf_object_type);
10001 +  PyModule_AddObject (gdb_module, "Membuf", (PyObject *) &membuf_object_type);
10002 +}
10003 diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
10004 index 434c8a5..b22c557 100644
10005 --- a/gdb/python/py-prettyprint.c
10006 +++ b/gdb/python/py-prettyprint.c
10007 @@ -204,10 +204,10 @@ pretty_print_one_value (PyObject *printer, struct value **out_value)
10008               && result != Py_None)
10009             {
10010               *out_value = convert_value_from_python (result);
10011 -             if (PyErr_Occurred ())
10012 -               *out_value = NULL;
10013 -             Py_DECREF (result);
10014 -             result = NULL;
10015 +             if (PyErr_Occurred ())
10016 +               *out_value = NULL;
10017 +             Py_DECREF (result);
10018 +             result = NULL;
10019             }
10020         }
10021      }
10022 @@ -700,14 +700,7 @@ gdbpy_get_varobj_pretty_printer (struct value *value)
10023  {
10024    PyObject *val_obj;
10025    PyObject *pretty_printer = NULL;
10026 -  volatile struct gdb_exception except;
10027  
10028 -  TRY_CATCH (except, RETURN_MASK_ALL)
10029 -    {
10030 -      value = value_copy (value);
10031 -    }
10032 -  GDB_PY_HANDLE_EXCEPTION (except);
10033 -  
10034    val_obj = value_to_value_object (value);
10035    if (! val_obj)
10036      return NULL;
10037 diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
10038 index b901255..4ff18e5 100644
10039 --- a/gdb/python/py-type.c
10040 +++ b/gdb/python/py-type.c
10041 @@ -27,6 +27,8 @@
10042  #include "demangle.h"
10043  #include "objfiles.h"
10044  #include "language.h"
10045 +#include "observer.h"
10046 +#include "gdb_assert.h"
10047  
10048  typedef struct pyty_type_object
10049  {
10050 @@ -35,11 +37,17 @@ typedef struct pyty_type_object
10051  
10052    /* If a Type object is associated with an objfile, it is kept on a
10053       doubly-linked list, rooted in the objfile.  This lets us copy the
10054 -     underlying struct type when the objfile is deleted.  */
10055 +     underlying struct type when the objfile is deleted.
10056 +
10057 +     With NULL objfile Type still can be doubly-linked in the list
10058 +     PYTY_OBJECTS_DISCARDABLE.  */
10059    struct pyty_type_object *prev;
10060    struct pyty_type_object *next;
10061  } type_object;
10062  
10063 +/* First element of a doubly-linked list of TYPE_DISCARDABLE Types.  */
10064 +static type_object *pyty_objects_discardable;
10065 +
10066  static PyTypeObject type_object_type;
10067  
10068  /* A Field object.  */
10069 @@ -618,8 +626,59 @@ typy_str (PyObject *self)
10070  
10071  \f
10072  
10073 +/* Key associated with each objfile pointing to the first element of
10074 +   a doubly-linked list of Types associated with this objfile.  */
10075  static const struct objfile_data *typy_objfile_data_key;
10076  
10077 +/* Link TYPE_OBJ to its appropriate list.  Either to its objfile associated one
10078 +   or at least to the global list for TYPE_DISCARDABLE Types.  Permanent types
10079 +   do not get linked anywhere.  */
10080 +static void
10081 +typy_link (type_object *type_obj)
10082 +{
10083 +  type_obj->prev = NULL;
10084 +
10085 +  if (type_obj->type && TYPE_OBJFILE (type_obj->type))
10086 +    {
10087 +      struct objfile *objfile = TYPE_OBJFILE (type_obj->type);
10088 +
10089 +      type_obj->next = objfile_data (objfile, typy_objfile_data_key);
10090 +      if (type_obj->next)
10091 +       type_obj->next->prev = type_obj;
10092 +      set_objfile_data (objfile, typy_objfile_data_key, type_obj);
10093 +    }
10094 +  else if (type_obj->type && TYPE_DISCARDABLE (type_obj->type))
10095 +    {
10096 +      type_obj->next = pyty_objects_discardable;
10097 +      if (type_obj->next)
10098 +       type_obj->next->prev = type_obj;
10099 +      pyty_objects_discardable = type_obj;
10100 +    }
10101 +  else
10102 +    type_obj->next = NULL;
10103 +}
10104 +
10105 +/* Unlink TYPE_OBJ from its current list.  Permanent types are not linked
10106 +   anywhere and this function has no effect on them.  */
10107 +static void
10108 +typy_unlink (type_object *type_obj)
10109 +{
10110 +  if (type_obj->prev)
10111 +    type_obj->prev->next = type_obj->next;
10112 +  else if (type_obj->type && TYPE_OBJFILE (type_obj->type))
10113 +    {
10114 +      /* Must reset head of list.  */
10115 +      struct objfile *objfile = TYPE_OBJFILE (type_obj->type);
10116 +
10117 +      set_objfile_data (objfile, typy_objfile_data_key, type_obj->next);
10118 +    }
10119 +  else if (pyty_objects_discardable == type_obj)
10120 +    pyty_objects_discardable = type_obj->next;
10121 +
10122 +  if (type_obj->next)
10123 +    type_obj->next->prev = type_obj->prev;
10124 +}
10125 +
10126  static void
10127  save_objfile_types (struct objfile *objfile, void *datum)
10128  {
10129 @@ -637,12 +696,13 @@ save_objfile_types (struct objfile *objfile, void *datum)
10130      {
10131        type_object *next = obj->next;
10132  
10133 -      htab_empty (copied_types);
10134 +      gdb_assert (TYPE_OBJFILE (obj->type) == objfile);
10135 +      typy_unlink (obj);
10136  
10137 -      obj->type = copy_type_recursive (objfile, obj->type, copied_types);
10138 +      obj->type = copy_type_recursive (obj->type, copied_types);
10139  
10140 -      obj->next = NULL;
10141 -      obj->prev = NULL;
10142 +      gdb_assert (TYPE_OBJFILE (obj->type) == NULL);
10143 +      typy_link (obj);
10144  
10145        obj = next;
10146      }
10147 @@ -653,42 +713,25 @@ save_objfile_types (struct objfile *objfile, void *datum)
10148  }
10149  
10150  static void
10151 -set_type (type_object *obj, struct type *type)
10152 +typy_dealloc (PyObject *obj)
10153  {
10154 -  obj->type = type;
10155 -  obj->prev = NULL;
10156 -  if (type && TYPE_OBJFILE (type))
10157 -    {
10158 -      struct objfile *objfile = TYPE_OBJFILE (type);
10159 +  type_object *type_obj = (type_object *) obj;
10160  
10161 -      obj->next = objfile_data (objfile, typy_objfile_data_key);
10162 -      if (obj->next)
10163 -       obj->next->prev = obj;
10164 -      set_objfile_data (objfile, typy_objfile_data_key, obj);
10165 -    }
10166 -  else
10167 -    obj->next = NULL;
10168 +  typy_unlink (type_obj);
10169 +
10170 +  type_obj->ob_type->tp_free (obj);
10171  }
10172  
10173 +/* Call type_mark_used for any TYPEs referenced from this GDB source file.  */
10174  static void
10175 -typy_dealloc (PyObject *obj)
10176 +typy_types_mark_used (void)
10177  {
10178 -  type_object *type = (type_object *) obj;
10179 -
10180 -  if (type->prev)
10181 -    type->prev->next = type->next;
10182 -  else if (type->type && TYPE_OBJFILE (type->type))
10183 -    {
10184 -      /* Must reset head of list.  */
10185 -      struct objfile *objfile = TYPE_OBJFILE (type->type);
10186 -
10187 -      if (objfile)
10188 -       set_objfile_data (objfile, typy_objfile_data_key, type->next);
10189 -    }
10190 -  if (type->next)
10191 -    type->next->prev = type->prev;
10192 +  type_object *type_obj;
10193  
10194 -  type->ob_type->tp_free (type);
10195 +  for (type_obj = pyty_objects_discardable;
10196 +       type_obj != NULL;
10197 +       type_obj = type_obj->next)
10198 +    type_mark_used (type_obj->type);
10199  }
10200  
10201  /* Create a new Type referring to TYPE.  */
10202 @@ -699,7 +742,10 @@ type_to_type_object (struct type *type)
10203  
10204    type_obj = PyObject_New (type_object, &type_object_type);
10205    if (type_obj)
10206 -    set_type (type_obj, type);
10207 +    {
10208 +      type_obj->type = type;
10209 +      typy_link (type_obj);
10210 +    }
10211  
10212    return (PyObject *) type_obj;
10213  }
10214 @@ -773,6 +819,8 @@ gdbpy_initialize_types (void)
10215  
10216    Py_INCREF (&field_object_type);
10217    PyModule_AddObject (gdb_module, "Field", (PyObject *) &field_object_type);
10218 +
10219 +  observer_attach_mark_used (typy_types_mark_used);
10220  }
10221  
10222  \f
10223 diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
10224 index 2024021..e8be12d 100644
10225 --- a/gdb/python/py-value.c
10226 +++ b/gdb/python/py-value.c
10227 @@ -25,6 +25,7 @@
10228  #include "language.h"
10229  #include "dfp.h"
10230  #include "valprint.h"
10231 +#include "observer.h"
10232  
10233  #ifdef HAVE_PYTHON
10234  
10235 @@ -1067,6 +1068,17 @@ gdbpy_is_value_object (PyObject *obj)
10236    return PyObject_TypeCheck (obj, &value_object_type);
10237  }
10238  
10239 +/* Call type_mark_used for any TYPEs referenced from this GDB source file.  */
10240 +
10241 +static void
10242 +python_types_mark_used (void)
10243 +{
10244 +  value_object *iter;
10245 +
10246 +  for (iter = values_in_python; iter; iter = iter->next)
10247 +    type_mark_used (value_type (iter->value));
10248 +}
10249 +
10250  void
10251  gdbpy_initialize_values (void)
10252  {
10253 @@ -1077,6 +1089,8 @@ gdbpy_initialize_values (void)
10254    PyModule_AddObject (gdb_module, "Value", (PyObject *) &value_object_type);
10255  
10256    values_in_python = NULL;
10257 +
10258 +  observer_attach_mark_used (python_types_mark_used);
10259  }
10260  
10261  \f
10262 diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
10263 index 2b8d301..0af99c8 100644
10264 --- a/gdb/python/python-internal.h
10265 +++ b/gdb/python/python-internal.h
10266 @@ -82,10 +82,11 @@ struct language_defn;
10267  struct program_space;
10268  
10269  extern PyObject *gdb_module;
10270 -extern PyTypeObject value_object_type;
10271  extern PyTypeObject block_object_type;
10272 +extern PyTypeObject value_object_type;
10273  extern PyTypeObject symbol_object_type;
10274  
10275 +/* Used in python-inferior.c.  */
10276  typedef struct
10277  {
10278    PyObject_HEAD
10279 @@ -126,6 +127,10 @@ PyObject *block_to_block_object (struct block *block, struct objfile *objfile);
10280  PyObject *value_to_value_object (struct value *v);
10281  PyObject *type_to_type_object (struct type *);
10282  PyObject *frame_info_to_frame_object (struct frame_info *frame);
10283 +PyObject *frame_info_to_frame_object (struct frame_info *frame);
10284 +thread_object *create_thread_object (struct thread_info *tp);
10285 +thread_object *find_thread_object (ptid_t ptid);
10286 +PyObject *find_inferior_object (int pid);
10287  
10288  PyObject *pspace_to_pspace_object (struct program_space *);
10289  PyObject *pspy_get_printers (PyObject *, void *);
10290 @@ -145,8 +150,11 @@ struct type *type_object_to_type (PyObject *obj);
10291  struct symtab *symtab_object_to_symtab (PyObject *obj);
10292  struct symtab_and_line *sal_object_to_symtab_and_line (PyObject *obj);
10293  
10294 +PyObject *gdbpy_get_hook_function (const char *);
10295  void gdbpy_initialize_auto_load (void);
10296 +
10297  void gdbpy_initialize_values (void);
10298 +void gdbpy_initialize_breakpoints (void);
10299  void gdbpy_initialize_frames (void);
10300  void gdbpy_initialize_symtabs (void);
10301  void gdbpy_initialize_commands (void);
10302 @@ -154,6 +162,7 @@ void gdbpy_initialize_symbols (void);
10303  void gdbpy_initialize_symtabs (void);
10304  void gdbpy_initialize_blocks (void);
10305  void gdbpy_initialize_types (void);
10306 +void gdbpy_initialize_blocks (void);
10307  void gdbpy_initialize_functions (void);
10308  void gdbpy_initialize_pspace (void);
10309  void gdbpy_initialize_objfile (void);
10310 @@ -171,6 +180,12 @@ struct cleanup *ensure_python_env (struct gdbarch *gdbarch,
10311  extern struct gdbarch *python_gdbarch;
10312  extern const struct language_defn *python_language;
10313  
10314 +char *gdbpy_parse_command_name (char *text,
10315 +                               struct cmd_list_element ***base_list,
10316 +                               struct cmd_list_element **start_list);
10317 +
10318 +PyObject *gdbpy_parameter_value (enum var_types, void *);
10319 +
10320  /* Use this after a TRY_EXCEPT to throw the appropriate Python
10321     exception.  */
10322  #define GDB_PY_HANDLE_EXCEPTION(Exception)                             \
10323 @@ -221,13 +236,14 @@ int gdbpy_is_value_object (PyObject *obj);
10324  PyObject *apply_varobj_pretty_printer (PyObject *print_obj,
10325                                        struct value **replacement);
10326  PyObject *gdbpy_get_varobj_pretty_printer (struct value *value);
10327 +PyObject *gdbpy_instantiate_printer (PyObject *cons, PyObject *value);
10328  char *gdbpy_get_display_hint (PyObject *printer);
10329  PyObject *gdbpy_default_visualizer (PyObject *self, PyObject *args);
10330  
10331 -extern PyObject *gdbpy_doc_cst;
10332  extern PyObject *gdbpy_children_cst;
10333  extern PyObject *gdbpy_to_string_cst;
10334  extern PyObject *gdbpy_display_hint_cst;
10335 +extern PyObject *gdbpy_doc_cst;
10336  extern PyObject *gdbpy_enabled_cst;
10337  
10338  extern PyObject *gdbpy_gdberror_exc;
10339 diff --git a/gdb/python/python.c b/gdb/python/python.c
10340 index 7346fba..34708c4 100644
10341 --- a/gdb/python/python.c
10342 +++ b/gdb/python/python.c
10343 @@ -28,6 +28,7 @@
10344  #include "value.h"
10345  #include "language.h"
10346  #include "exceptions.h"
10347 +#include "event-loop.h"
10348  
10349  #include <ctype.h>
10350  
10351 @@ -42,10 +43,17 @@ static int gdbpy_should_print_stack = 1;
10352  #include "cli/cli-decode.h"
10353  #include "charset.h"
10354  #include "top.h"
10355 +#include "solib.h"
10356  #include "python-internal.h"
10357 +#include "linespec.h"
10358 +#include "symtab.h"
10359 +#include "source.h"
10360  #include "version.h"
10361 +#include "inferior.h"
10362 +#include "gdbthread.h"
10363  #include "target.h"
10364  #include "gdbthread.h"
10365 +#include "event-top.h"
10366  
10367  static PyMethodDef GdbMethods[];
10368  
10369 @@ -374,6 +382,105 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
10370    Py_RETURN_NONE;
10371  }
10372  
10373 +/* Implementation of gdb.solib_address (Long) -> String.
10374 +   Returns the name of the shared library holding a given address, or None.  */
10375 +
10376 +static PyObject *
10377 +gdbpy_solib_address (PyObject *self, PyObject *args)
10378 +{
10379 +  unsigned long long pc;
10380 +  char *soname;
10381 +  PyObject *str_obj;
10382 +
10383 +  if (!PyArg_ParseTuple (args, "K", &pc))
10384 +    return NULL;
10385 +
10386 +  soname = solib_name_from_address (current_program_space, pc);
10387 +  if (soname)
10388 +    str_obj = PyString_Decode (soname, strlen (soname), host_charset (), NULL);
10389 +  else
10390 +    {
10391 +      str_obj = Py_None;
10392 +      Py_INCREF (Py_None);
10393 +    }
10394 +
10395 +  return str_obj;
10396 +}
10397 +
10398 +/* A Python function which is a wrapper for decode_line_1.  */
10399 +
10400 +static PyObject *
10401 +gdbpy_decode_line (PyObject *self, PyObject *args)
10402 +{
10403 +  struct symtabs_and_lines sals = { NULL, 0 }; /* Initialize to appease gcc.  */
10404 +  struct symtab_and_line sal;
10405 +  char *arg = NULL;
10406 +  int free_sals = 0, i;
10407 +  PyObject *result = NULL;
10408 +  volatile struct gdb_exception except;
10409 +
10410 +  if (! PyArg_ParseTuple (args, "|s", &arg))
10411 +    return NULL;
10412 +
10413 +  TRY_CATCH (except, RETURN_MASK_ALL)
10414 +    {
10415 +      if (arg)
10416 +       {
10417 +         char *copy;
10418 +
10419 +         arg = strdup (arg);
10420 +         copy = arg;
10421 +
10422 +         sals = decode_line_1 (&copy, 0, 0, 0, 0, 0);
10423 +         free_sals = 1;
10424 +       }
10425 +      else
10426 +       {
10427 +         set_default_source_symtab_and_line ();
10428 +         sal = get_current_source_symtab_and_line ();
10429 +         sals.sals = &sal;
10430 +         sals.nelts = 1;
10431 +       }
10432 +    }
10433 +  if (arg)
10434 +    xfree (arg);
10435 +
10436 +  if (except.reason < 0)
10437 +    {
10438 +      if (free_sals)
10439 +       xfree (sals.sals);
10440 +      /* We know this will always throw.  */
10441 +      GDB_PY_HANDLE_EXCEPTION (except);
10442 +    }
10443 +
10444 +  if (sals.nelts)
10445 +    {
10446 +      result = PyTuple_New (sals.nelts);
10447 +      for (i = 0; i < sals.nelts; ++i)
10448 +       {
10449 +         PyObject *obj;
10450 +         char *str;
10451 +
10452 +         obj = symtab_and_line_to_sal_object (sals.sals[i]);
10453 +         if (! obj)
10454 +           {
10455 +             Py_DECREF (result);
10456 +             result = NULL;
10457 +             break;
10458 +           }
10459 +
10460 +         PyTuple_SetItem (result, i, obj);
10461 +       }
10462 +    }
10463 +
10464 +  if (free_sals)
10465 +    xfree (sals.sals);
10466 +
10467 +  if (result)
10468 +    return result;
10469 +  Py_RETURN_NONE;
10470 +}
10471 +
10472  /* Parse a string and evaluate it as an expression.  */
10473  static PyObject *
10474  gdbpy_parse_and_eval (PyObject *self, PyObject *args)
10475 @@ -414,6 +521,114 @@ source_python_script (FILE *stream, const char *file)
10476  
10477  \f
10478  
10479 +/* Posting and handling events.  */
10480 +
10481 +/* A single event.  */
10482 +struct gdbpy_event
10483 +{
10484 +  /* The Python event.  This is just a callable object.  */
10485 +  PyObject *event;
10486 +  /* The next event.  */
10487 +  struct gdbpy_event *next;
10488 +};
10489 +
10490 +/* All pending events.  */
10491 +static struct gdbpy_event *gdbpy_event_list;
10492 +/* The final link of the event list.  */
10493 +static struct gdbpy_event **gdbpy_event_list_end;
10494 +
10495 +/* We use a file handler, and not an async handler, so that we can
10496 +   wake up the main thread even when it is blocked in poll().  */
10497 +static int gdbpy_event_fds[2];
10498 +
10499 +/* The file handler callback.  This reads from the internal pipe, and
10500 +   then processes the Python event queue.  This will always be run in
10501 +   the main gdb thread.  */
10502 +static void
10503 +gdbpy_run_events (int err, gdb_client_data ignore)
10504 +{
10505 +  struct cleanup *cleanup;
10506 +  char buffer[100];
10507 +  int r;
10508 +
10509 +  cleanup = ensure_python_env (get_current_arch (), current_language);
10510 +
10511 +  /* Just read whatever is available on the fd.  It is relatively
10512 +     harmless if there are any bytes left over.  */
10513 +  r = read (gdbpy_event_fds[0], buffer, sizeof (buffer));
10514 +
10515 +  while (gdbpy_event_list)
10516 +    {
10517 +      /* Dispatching the event might push a new element onto the event
10518 +        loop, so we update here "atomically enough".  */
10519 +      struct gdbpy_event *item = gdbpy_event_list;
10520 +      gdbpy_event_list = gdbpy_event_list->next;
10521 +      if (gdbpy_event_list == NULL)
10522 +       gdbpy_event_list_end = &gdbpy_event_list;
10523 +
10524 +      /* Ignore errors.  */
10525 +      PyObject_CallObject (item->event, NULL);
10526 +
10527 +      Py_DECREF (item->event);
10528 +      xfree (item);
10529 +    }
10530 +
10531 +  do_cleanups (cleanup);
10532 +}
10533 +
10534 +/* Submit an event to the gdb thread.  */
10535 +static PyObject *
10536 +gdbpy_post_event (PyObject *self, PyObject *args)
10537 +{
10538 +  struct gdbpy_event *event;
10539 +  PyObject *func;
10540 +  int wakeup;
10541 +
10542 +  if (!PyArg_ParseTuple (args, "O", &func))
10543 +    return NULL;
10544 +
10545 +  if (!PyCallable_Check (func))
10546 +    {
10547 +      PyErr_SetString (PyExc_RuntimeError, "Posted event is not callable");
10548 +      return NULL;
10549 +    }
10550 +
10551 +  Py_INCREF (func);
10552 +
10553 +  /* From here until the end of the function, we have the GIL, so we
10554 +     can operate on our global data structures without worrying.  */
10555 +  wakeup = gdbpy_event_list == NULL;
10556 +
10557 +  event = XNEW (struct gdbpy_event);
10558 +  event->event = func;
10559 +  event->next = NULL;
10560 +  *gdbpy_event_list_end = event;
10561 +  gdbpy_event_list_end = &event->next;
10562 +
10563 +  /* Wake up gdb when needed.  */
10564 +  if (wakeup)
10565 +    {
10566 +      char c = 'q';            /* Anything. */
10567 +      if (write (gdbpy_event_fds[1], &c, 1) != 1)
10568 +        return PyErr_SetFromErrno (PyExc_IOError);
10569 +    }
10570 +
10571 +  Py_RETURN_NONE;
10572 +}
10573 +
10574 +/* Initialize the Python event handler.  */
10575 +static void
10576 +gdbpy_initialize_events (void)
10577 +{
10578 +  if (!pipe (gdbpy_event_fds))
10579 +    {
10580 +      gdbpy_event_list_end = &gdbpy_event_list;
10581 +      add_file_handler (gdbpy_event_fds[0], gdbpy_run_events, NULL);
10582 +    }
10583 +}
10584 +
10585 +\f
10586 +
10587  /* Printing.  */
10588  
10589  /* A python function to write a single string using gdb's filtered
10590 @@ -459,6 +674,53 @@ gdbpy_print_stack (void)
10591  
10592  /* Return the current Progspace.
10593     There always is one.  */
10594 +/* True if 'gdb -P' was used, false otherwise.  */
10595 +static int running_python_script;
10596 +
10597 +/* True if we are currently in a call to 'gdb.cli', false otherwise.  */
10598 +static int in_cli;
10599 +
10600 +/* Enter the command loop.  */
10601 +
10602 +static PyObject *
10603 +gdbpy_cli (PyObject *unused1, PyObject *unused2)
10604 +{
10605 +  if (! running_python_script || in_cli)
10606 +    return PyErr_Format (PyExc_RuntimeError, "cannot invoke CLI recursively");
10607 +
10608 +  in_cli = 1;
10609 +  cli_command_loop ();
10610 +  in_cli = 0;
10611 +
10612 +  Py_RETURN_NONE;
10613 +}
10614 +
10615 +/* Set up the Python argument vector and evaluate a script.  This is
10616 +   used to implement 'gdb -P'.  */
10617 +
10618 +void
10619 +run_python_script (int argc, char **argv)
10620 +{
10621 +  FILE *input;
10622 +
10623 +  /* We never free this, since we plan to exit at the end.  */
10624 +  ensure_python_env (get_current_arch (), current_language);
10625 +
10626 +  running_python_script = 1;
10627 +  PySys_SetArgv (argc - 1, argv + 1);
10628 +  input = fopen (argv[0], "r");
10629 +  if (! input)
10630 +    {
10631 +      fprintf (stderr, "could not open %s: %s\n", argv[0], strerror (errno));
10632 +      exit (1);
10633 +    }
10634 +  PyRun_SimpleFile (input, argv[0]);
10635 +  fclose (input);
10636 +  exit (0);
10637 +}
10638 +
10639 +\f
10640 +
10641  
10642  static PyObject *
10643  gdbpy_get_current_progspace (PyObject *unused1, PyObject *unused2)
10644 @@ -720,6 +982,7 @@ Enables or disables printing of Python stack traces."),
10645    gdbpy_initialize_lazy_string ();
10646    gdbpy_initialize_thread ();
10647    gdbpy_initialize_inferior ();
10648 +  gdbpy_initialize_events ();
10649  
10650    PyRun_SimpleString ("import gdb");
10651    PyRun_SimpleString ("gdb.pretty_printers = []");
10652 @@ -787,6 +1050,8 @@ static PyMethodDef GdbMethods[] =
10653      "Get a value from history" },
10654    { "execute", (PyCFunction) execute_gdb_command, METH_VARARGS | METH_KEYWORDS,
10655      "Execute a gdb command" },
10656 +  { "cli", gdbpy_cli, METH_NOARGS,
10657 +    "Enter the gdb CLI" },
10658    { "parameter", gdbpy_parameter, METH_VARARGS,
10659      "Return a gdb parameter's value" },
10660  
10661 @@ -825,11 +1090,21 @@ a boolean indicating if name is a field of the current implied argument\n\
10662  `this' (when the current language is object-oriented)." },
10663    { "block_for_pc", gdbpy_block_for_pc, METH_VARARGS,
10664      "Return the block containing the given pc value, or None." },
10665 +  { "solib_address", gdbpy_solib_address, METH_VARARGS,
10666 +    "solib_address (Long) -> String.\n\
10667 +Return the name of the shared library holding a given address, or None." },
10668 +  { "decode_line", gdbpy_decode_line, METH_VARARGS,
10669 +    "Decode a string argument the way that 'break' or 'edit' does.\n\
10670 +Return a tuple holding the file name (or None) and line number (or None).\n\
10671 +Note: may later change to return an object." },
10672    { "parse_and_eval", gdbpy_parse_and_eval, METH_VARARGS,
10673      "parse_and_eval (String) -> Value.\n\
10674  Parse String as an expression, evaluate it, and return the result as a Value."
10675    },
10676  
10677 +  { "post_event", gdbpy_post_event, METH_VARARGS,
10678 +    "Post an event into gdb's event loop." },
10679 +
10680    { "target_charset", gdbpy_target_charset, METH_NOARGS,
10681      "target_charset () -> string.\n\
10682  Return the name of the current target charset." },
10683 diff --git a/gdb/python/python.h b/gdb/python/python.h
10684 index affd4a4..5407878 100644
10685 --- a/gdb/python/python.h
10686 +++ b/gdb/python/python.h
10687 @@ -28,6 +28,8 @@ void eval_python_from_control_command (struct command_line *);
10688  
10689  void source_python_script (FILE *stream, const char *file);
10690  
10691 +void run_python_script (int argc, char **argv);
10692 +
10693  int apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
10694                               int embedded_offset, CORE_ADDR address,
10695                               struct ui_file *stream, int recurse,
10696 diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
10697 index 1f135d4..489838d 100644
10698 --- a/gdb/solib-svr4.c
10699 +++ b/gdb/solib-svr4.c
10700 @@ -1278,7 +1278,8 @@ svr4_in_dynsym_resolve_code (CORE_ADDR pc)
10701            && pc < info->interp_text_sect_high)
10702           || (pc >= info->interp_plt_sect_low
10703               && pc < info->interp_plt_sect_high)
10704 -         || in_plt_section (pc, NULL));
10705 +         || in_plt_section (pc, NULL)
10706 +         || in_gnu_ifunc_stub (pc));
10707  }
10708  
10709  /* Given an executable's ABFD and target, compute the entry-point
10710 diff --git a/gdb/symfile.c b/gdb/symfile.c
10711 index 42f7ae3..371db0d 100644
10712 --- a/gdb/symfile.c
10713 +++ b/gdb/symfile.c
10714 @@ -1059,6 +1059,9 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
10715    const char *name = bfd_get_filename (abfd);
10716    const int from_tty = add_flags & SYMFILE_VERBOSE;
10717  
10718 +  if (readnow_symbol_files)
10719 +    flags |= OBJF_READNOW;
10720 +
10721    my_cleanups = make_cleanup_bfd_close (abfd);
10722  
10723    /* Give user a chance to burp if we'd be
10724 @@ -1095,7 +1098,7 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
10725       the gdb startup command line or on a per symbol file basis.  Expand
10726       all partial symbol tables for this objfile if so. */
10727  
10728 -  if ((flags & OBJF_READNOW) || readnow_symbol_files)
10729 +  if ((flags & OBJF_READNOW))
10730      {
10731        if (from_tty || info_verbose)
10732         {
10733 @@ -1533,7 +1536,7 @@ symbol_file_command (char *args, int from_tty)
10734  void
10735  set_initial_language (void)
10736  {
10737 -  char *filename;
10738 +  const char *filename;
10739    enum language lang = language_unknown;
10740  
10741    filename = find_main_filename ();
10742 @@ -2660,7 +2663,7 @@ init_filename_language_table (void)
10743  }
10744  
10745  enum language
10746 -deduce_language_from_filename (char *filename)
10747 +deduce_language_from_filename (const char *filename)
10748  {
10749    int i;
10750    char *cp;
10751 diff --git a/gdb/symfile.h b/gdb/symfile.h
10752 index d53c465..5815354 100644
10753 --- a/gdb/symfile.h
10754 +++ b/gdb/symfile.h
10755 @@ -171,6 +171,15 @@ struct quick_symbol_functions
10756                                    int kind, const char *name,
10757                                    domain_enum domain);
10758  
10759 +  /* This is called to expand symbol tables before looking up a
10760 +     symbol.  A backend can choose to implement this and then have its
10761 +     `lookup_symbol' hook always return NULL, or the reverse.  (It
10762 +     doesn't make sense to implement both.)  The arguments are as for
10763 +     `lookup_symbol'.  */
10764 +  void (*pre_expand_symtabs_matching) (struct objfile *objfile,
10765 +                                      int kind, const char *name,
10766 +                                      domain_enum domain);
10767 +
10768    /* Print statistics about any indices loaded for OBJFILE.  The
10769       statistics should be printed to gdb_stdout.  This is used for
10770       "maint print statistics".  */
10771 @@ -201,7 +210,7 @@ struct quick_symbol_functions
10772  
10773    /* Return the file name of the file holding the symbol in OBJFILE
10774       named NAME.  If no such symbol exists in OBJFILE, return NULL.  */
10775 -  char *(*find_symbol_file) (struct objfile *objfile, const char *name);
10776 +  const char *(*find_symbol_file) (struct objfile *objfile, const char *name);
10777  
10778    /* This method is specific to Ada.  It walks the partial symbol
10779       tables of OBJFILE looking for a name match.  WILD_MATCH and
10780 @@ -566,6 +575,7 @@ extern struct cleanup *increment_reading_symtab (void);
10781  
10782  extern int dwarf2_has_info (struct objfile *);
10783  
10784 +extern int dwarf2_initialize_objfile (struct objfile *);
10785  extern void dwarf2_build_psymtabs (struct objfile *);
10786  extern void dwarf2_build_frame_info (struct objfile *);
10787  
10788 diff --git a/gdb/symmisc.c b/gdb/symmisc.c
10789 index 62e6b97..00dc613 100644
10790 --- a/gdb/symmisc.c
10791 +++ b/gdb/symmisc.c
10792 @@ -262,6 +262,9 @@ dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
10793         case mst_text:
10794           ms_type = 'T';
10795           break;
10796 +       case mst_text_gnu_ifunc:
10797 +         ms_type = 'i';
10798 +         break;
10799         case mst_solib_trampoline:
10800           ms_type = 'S';
10801           break;
10802 diff --git a/gdb/symtab.c b/gdb/symtab.c
10803 index 2c4c9e4..28f0450 100644
10804 --- a/gdb/symtab.c
10805 +++ b/gdb/symtab.c
10806 @@ -1295,16 +1295,25 @@ lookup_symbol_aux_symtabs (int block_index, const char *name,
10807    const struct block *block;
10808    struct symtab *s;
10809  
10810 -  ALL_PRIMARY_SYMTABS (objfile, s)
10811 +  ALL_OBJFILES (objfile)
10812    {
10813 -    bv = BLOCKVECTOR (s);
10814 -    block = BLOCKVECTOR_BLOCK (bv, block_index);
10815 -    sym = lookup_block_symbol (block, name, domain);
10816 -    if (sym)
10817 -      {
10818 -       block_found = block;
10819 -       return fixup_symbol_section (sym, objfile);
10820 -      }
10821 +    if (objfile->sf)
10822 +      objfile->sf->qf->pre_expand_symtabs_matching (objfile,
10823 +                                                   block_index,
10824 +                                                   name, domain);
10825 +
10826 +    ALL_OBJFILE_SYMTABS (objfile, s)
10827 +      if (s->primary)
10828 +       {
10829 +         bv = BLOCKVECTOR (s);
10830 +         block = BLOCKVECTOR_BLOCK (bv, block_index);
10831 +         sym = lookup_block_symbol (block, name, domain);
10832 +         if (sym)
10833 +           {
10834 +             block_found = block;
10835 +             return fixup_symbol_section (sym, objfile);
10836 +           }
10837 +       }
10838    }
10839  
10840    return NULL;
10841 @@ -1547,15 +1556,24 @@ basic_lookup_transparent_type (const char *name)
10842       of the desired name as a global, then do psymtab-to-symtab
10843       conversion on the fly and return the found symbol.  */
10844  
10845 -  ALL_PRIMARY_SYMTABS (objfile, s)
10846 +  ALL_OBJFILES (objfile)
10847    {
10848 -    bv = BLOCKVECTOR (s);
10849 -    block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
10850 -    sym = lookup_block_symbol (block, name, STRUCT_DOMAIN);
10851 -    if (sym && !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
10852 -      {
10853 -       return SYMBOL_TYPE (sym);
10854 -      }
10855 +    if (objfile->sf)
10856 +      objfile->sf->qf->pre_expand_symtabs_matching (objfile,
10857 +                                                   GLOBAL_BLOCK,
10858 +                                                   name, STRUCT_DOMAIN);
10859 +
10860 +    ALL_OBJFILE_SYMTABS (objfile, s)
10861 +      if (s->primary)
10862 +       {
10863 +         bv = BLOCKVECTOR (s);
10864 +         block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
10865 +         sym = lookup_block_symbol (block, name, STRUCT_DOMAIN);
10866 +         if (sym && !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
10867 +           {
10868 +             return SYMBOL_TYPE (sym);
10869 +           }
10870 +       }
10871    }
10872  
10873    ALL_OBJFILES (objfile)
10874 @@ -1599,14 +1617,16 @@ basic_lookup_transparent_type (const char *name)
10875  /* FIXME:  What about languages without main() or specially linked
10876     executables that have no main() ? */
10877  
10878 -char *
10879 +const char *
10880  find_main_filename (void)
10881  {
10882    struct objfile *objfile;
10883 -  char *result, *name = main_name ();
10884 +  char *name = main_name ();
10885  
10886    ALL_OBJFILES (objfile)
10887    {
10888 +    const char *result;
10889 +
10890      if (!objfile->sf)
10891        continue;
10892      result = objfile->sf->qf->find_symbol_file (objfile, name);
10893 @@ -2914,7 +2934,7 @@ search_symbols (char *regexp, domain_enum kind, int nfiles, char *files[],
10894    static enum minimal_symbol_type types3[]
10895      = {mst_file_data, mst_solib_trampoline, mst_abs, mst_unknown};
10896    static enum minimal_symbol_type types4[]
10897 -    = {mst_file_bss, mst_text, mst_abs, mst_unknown};
10898 +    = {mst_file_bss, mst_text_gnu_ifunc, mst_abs, mst_unknown};
10899    enum minimal_symbol_type ourtype;
10900    enum minimal_symbol_type ourtype2;
10901    enum minimal_symbol_type ourtype3;
10902 diff --git a/gdb/symtab.h b/gdb/symtab.h
10903 index bedc10a..dc284e4 100644
10904 --- a/gdb/symtab.h
10905 +++ b/gdb/symtab.h
10906 @@ -277,6 +277,9 @@ enum minimal_symbol_type
10907  {
10908    mst_unknown = 0,             /* Unknown type, the default */
10909    mst_text,                    /* Generally executable instructions */
10910 +  mst_text_gnu_ifunc,          /* Executable code returning address
10911 +                                  of executable code */
10912 +  mst_slot_got_plt,
10913    mst_data,                    /* Generally initialized data */
10914    mst_bss,                     /* Generally uninitialized data */
10915    mst_abs,                     /* Generally absolute (nonrelocatable) */
10916 @@ -917,11 +920,25 @@ extern struct symbol *find_pc_sect_function (CORE_ADDR, struct obj_section *);
10917  
10918  /* lookup function from address, return name, start addr and end addr */
10919  
10920 -extern int find_pc_partial_function (CORE_ADDR, char **, CORE_ADDR *,
10921 -                                    CORE_ADDR *);
10922 +extern enum find_pc_partial_function_type
10923 +  {
10924 +    FIND_PC_PARTIAL_FUNCTION_NOT_FOUND = 0,
10925 +    FIND_PC_PARTIAL_FUNCTION_NORMAL,
10926 +    FIND_PC_PARTIAL_FUNCTION_GNU_IFUNC
10927 +  } find_pc_partial_function (CORE_ADDR, char **, CORE_ADDR *, CORE_ADDR *);
10928  
10929  extern void clear_pc_function_cache (void);
10930  
10931 +extern int resolve_gnu_ifunc (const char *function_name,
10932 +                             CORE_ADDR *function_addressp);
10933 +
10934 +extern struct minimal_symbol *resolve_gnu_ifunc_by_cache
10935 +  (const char *function_name);
10936 +
10937 +extern void gnu_ifunc_record_cache (struct gdbarch *gdbarch,
10938 +                                   const char *function_name,
10939 +                                   CORE_ADDR function_address);
10940 +
10941  /* lookup partial symbol table by address and section */
10942  
10943  extern struct symtab *find_pc_sect_symtab_via_partial (CORE_ADDR,
10944 @@ -996,6 +1013,8 @@ extern struct minimal_symbol *lookup_minimal_symbol_by_pc_name
10945  
10946  extern struct minimal_symbol *lookup_minimal_symbol_by_pc (CORE_ADDR);
10947  
10948 +extern int in_gnu_ifunc_stub (CORE_ADDR pc);
10949 +
10950  extern struct minimal_symbol *
10951      lookup_minimal_symbol_and_objfile (const char *,
10952                                        struct objfile **);
10953 @@ -1137,7 +1156,7 @@ extern char **make_source_files_completion_list (char *, char *);
10954  
10955  int matching_obj_sections (struct obj_section *, struct obj_section *);
10956  
10957 -extern char *find_main_filename (void);
10958 +extern const char *find_main_filename (void);
10959  
10960  extern struct symtab *find_line_symtab (struct symtab *, int, int *, int *);
10961  
10962 @@ -1150,7 +1169,7 @@ extern void skip_prologue_sal (struct symtab_and_line *);
10963  
10964  extern void clear_symtab_users (void);
10965  
10966 -extern enum language deduce_language_from_filename (char *);
10967 +extern enum language deduce_language_from_filename (const char *);
10968  
10969  /* symtab.c */
10970  
10971 diff --git a/gdb/target.c b/gdb/target.c
10972 index 4cabcbd..34b3b60 100644
10973 --- a/gdb/target.c
10974 +++ b/gdb/target.c
10975 @@ -123,6 +123,8 @@ static int debug_to_insert_watchpoint (CORE_ADDR, int, int,
10976  static int debug_to_remove_watchpoint (CORE_ADDR, int, int,
10977                                        struct expression *);
10978  
10979 +static int debug_to_detach_watchpoints (void);
10980 +
10981  static int debug_to_stopped_by_watchpoint (void);
10982  
10983  static int debug_to_stopped_data_address (struct target_ops *, CORE_ADDR *);
10984 @@ -606,6 +608,7 @@ update_current_target (void)
10985        INHERIT (to_remove_hw_breakpoint, t);
10986        INHERIT (to_insert_watchpoint, t);
10987        INHERIT (to_remove_watchpoint, t);
10988 +      INHERIT (to_detach_watchpoints, t);
10989        INHERIT (to_stopped_data_address, t);
10990        INHERIT (to_have_steppable_watchpoint, t);
10991        INHERIT (to_have_continuable_watchpoint, t);
10992 @@ -739,6 +742,9 @@ update_current_target (void)
10993    de_fault (to_remove_watchpoint,
10994             (int (*) (CORE_ADDR, int, int, struct expression *))
10995             return_minus_one);
10996 +  de_fault (to_detach_watchpoints,
10997 +           (int (*) (void))
10998 +           return_zero);
10999    de_fault (to_stopped_by_watchpoint,
11000             (int (*) (void))
11001             return_zero);
11002 @@ -3440,6 +3446,19 @@ debug_to_remove_watchpoint (CORE_ADDR addr, int len, int type,
11003    return retval;
11004  }
11005  
11006 +static int
11007 +debug_to_detach_watchpoints (void)
11008 +{
11009 +  int retval;
11010 +
11011 +  retval = debug_target.to_detach_watchpoints ();
11012 +
11013 +  fprintf_unfiltered (gdb_stdlog,
11014 +                     "target_detach_watchpoints () = %ld\n",
11015 +                     (unsigned long) retval);
11016 +  return retval;
11017 +}
11018 +
11019  static void
11020  debug_to_terminal_init (void)
11021  {
11022 @@ -3687,6 +3706,7 @@ setup_target_debug (void)
11023    current_target.to_remove_hw_breakpoint = debug_to_remove_hw_breakpoint;
11024    current_target.to_insert_watchpoint = debug_to_insert_watchpoint;
11025    current_target.to_remove_watchpoint = debug_to_remove_watchpoint;
11026 +  current_target.to_detach_watchpoints = debug_to_detach_watchpoints;
11027    current_target.to_stopped_by_watchpoint = debug_to_stopped_by_watchpoint;
11028    current_target.to_stopped_data_address = debug_to_stopped_data_address;
11029    current_target.to_watchpoint_addr_within_range = debug_to_watchpoint_addr_within_range;
11030 diff --git a/gdb/target.h b/gdb/target.h
11031 index 3c8c017..608a742 100644
11032 --- a/gdb/target.h
11033 +++ b/gdb/target.h
11034 @@ -433,6 +433,7 @@ struct target_ops
11035         provided with the corresponding target_* macros.  */
11036      int (*to_remove_watchpoint) (CORE_ADDR, int, int, struct expression *);
11037      int (*to_insert_watchpoint) (CORE_ADDR, int, int, struct expression *);
11038 +    int (*to_detach_watchpoints) (void);
11039  
11040      int (*to_stopped_by_watchpoint) (void);
11041      int to_have_steppable_watchpoint;
11042 @@ -1316,6 +1317,15 @@ extern char *normal_pid_to_str (ptid_t ptid);
11043  #define        target_remove_watchpoint(addr, len, type, cond) \
11044       (*current_target.to_remove_watchpoint) (addr, len, type, cond)
11045  
11046 +/* Clear all debug registers without affecting any register caches.  Function
11047 +   acts on INFERIOR_PTID which should be the forked-off process, either the
11048 +   non-threaded child one or the threaded parent one, depending on `set
11049 +   follow-fork-mode'.  Both watchpoints and hardware breakpoints get removed.
11050 +   Return 0 on success, -1 on failure.  */
11051 +
11052 +#define        target_detach_watchpoints()     \
11053 +     (*current_target.to_detach_watchpoints) ()
11054 +
11055  #define target_insert_hw_breakpoint(gdbarch, bp_tgt) \
11056       (*current_target.to_insert_hw_breakpoint) (gdbarch, bp_tgt)
11057  
11058 @@ -1369,6 +1379,18 @@ extern int target_search_memory (CORE_ADDR start_addr,
11059                                   ULONGEST pattern_len,
11060                                   CORE_ADDR *found_addrp);
11061  
11062 +/* Utility functions which can be used by search_memory implementations.  */
11063 +
11064 +void allocate_pattern_buffer (char **pattern_bufp, char **pattern_buf_end,
11065 +                             ULONGEST *pattern_buf_size);
11066 +
11067 +void increase_pattern_buffer (char **pattern_bufp, char **pattern_buf_end,
11068 +                             ULONGEST *pattern_buf_size, int val_bytes);
11069 +
11070 +int search_memory (CORE_ADDR *start_addr, ULONGEST *search_space_len,
11071 +                  const char *pattern_buf, ULONGEST pattern_len,
11072 +                  CORE_ADDR *found_addr);
11073 +
11074  /* Tracepoint-related operations.  */
11075  
11076  #define target_trace_init() \
11077 diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-pointer-foo.S b/gdb/testsuite/gdb.arch/x86_64-vla-pointer-foo.S
11078 new file mode 100644
11079 index 0000000..83faaf6
11080 --- /dev/null
11081 +++ b/gdb/testsuite/gdb.arch/x86_64-vla-pointer-foo.S
11082 @@ -0,0 +1,457 @@
11083 +       .file   "x86_64-vla-pointer.c"
11084 +       .section        .debug_abbrev,"",@progbits
11085 +.Ldebug_abbrev0:
11086 +       .section        .debug_info,"",@progbits
11087 +.Ldebug_info0:
11088 +       .section        .debug_line,"",@progbits
11089 +.Ldebug_line0:
11090 +       .text
11091 +.Ltext0:
11092 +.globl foo
11093 +       .type   foo, @function
11094 +foo:
11095 +.LFB2:
11096 +       .file 1 "x86_64-vla-pointer.c"
11097 +       .loc 1 22 0
11098 +       pushq   %rbp
11099 +.LCFI0:
11100 +       movq    %rsp, %rbp
11101 +.LCFI1:
11102 +       subq    $64, %rsp
11103 +.LCFI2:
11104 +       movl    %edi, -36(%rbp)
11105 +       .loc 1 22 0
11106 +       movq    %rsp, %rax
11107 +       movq    %rax, -48(%rbp)
11108 +       .loc 1 23 0
11109 +       movl    -36(%rbp), %edx
11110 +       movslq  %edx,%rax
11111 +       subq    $1, %rax
11112 +       movq    %rax, -24(%rbp)
11113 +       .loc 1 24 0
11114 +       movslq  %edx,%rax
11115 +       addq    $15, %rax
11116 +       addq    $15, %rax
11117 +       shrq    $4, %rax
11118 +       salq    $4, %rax
11119 +       subq    %rax, %rsp
11120 +       movq    %rsp, -56(%rbp)
11121 +       movq    -56(%rbp), %rax
11122 +       addq    $15, %rax
11123 +       shrq    $4, %rax
11124 +       salq    $4, %rax
11125 +       movq    %rax, -56(%rbp)
11126 +       movq    -56(%rbp), %rax
11127 +       movq    %rax, -16(%rbp)
11128 +       .loc 1 27 0
11129 +       movl    $0, -4(%rbp)
11130 +       jmp     .L2
11131 +.L3:
11132 +       .loc 1 28 0
11133 +       movl    -4(%rbp), %esi
11134 +       movl    -4(%rbp), %eax
11135 +       movl    %eax, %ecx
11136 +       movq    -16(%rbp), %rdx
11137 +       movslq  %esi,%rax
11138 +       movb    %cl, (%rdx,%rax)
11139 +       .loc 1 27 0
11140 +       addl    $1, -4(%rbp)
11141 +.L2:
11142 +       movl    -4(%rbp), %eax
11143 +       cmpl    -36(%rbp), %eax
11144 +       jl      .L3
11145 +       .loc 1 30 0
11146 +       .globl  break_here
11147 +break_here:
11148 +       movq    -16(%rbp), %rax
11149 +       movb    $0, (%rax)
11150 +       movq    -48(%rbp), %rsp
11151 +       .loc 1 31 0
11152 +       leave
11153 +       ret
11154 +.LFE2:
11155 +       .size   foo, .-foo
11156 +       .section        .debug_frame,"",@progbits
11157 +.Lframe0:
11158 +       .long   .LECIE0-.LSCIE0
11159 +.LSCIE0:
11160 +       .long   0xffffffff
11161 +       .byte   0x1
11162 +       .string ""
11163 +       .uleb128 0x1
11164 +       .sleb128 -8
11165 +       .byte   0x10
11166 +       .byte   0xc
11167 +       .uleb128 0x7
11168 +       .uleb128 0x8
11169 +       .byte   0x90
11170 +       .uleb128 0x1
11171 +       .align 8
11172 +.LECIE0:
11173 +.LSFDE0:
11174 +       .long   .LEFDE0-.LASFDE0
11175 +.LASFDE0:
11176 +       .long   .Lframe0
11177 +       .quad   .LFB2
11178 +       .quad   .LFE2-.LFB2
11179 +       .byte   0x4
11180 +       .long   .LCFI0-.LFB2
11181 +       .byte   0xe
11182 +       .uleb128 0x10
11183 +       .byte   0x86
11184 +       .uleb128 0x2
11185 +       .byte   0x4
11186 +       .long   .LCFI1-.LCFI0
11187 +       .byte   0xd
11188 +       .uleb128 0x6
11189 +       .align 8
11190 +.LEFDE0:
11191 +       .section        .eh_frame,"a",@progbits
11192 +.Lframe1:
11193 +       .long   .LECIE1-.LSCIE1
11194 +.LSCIE1:
11195 +       .long   0x0
11196 +       .byte   0x1
11197 +       .string "zR"
11198 +       .uleb128 0x1
11199 +       .sleb128 -8
11200 +       .byte   0x10
11201 +       .uleb128 0x1
11202 +       .byte   0x3
11203 +       .byte   0xc
11204 +       .uleb128 0x7
11205 +       .uleb128 0x8
11206 +       .byte   0x90
11207 +       .uleb128 0x1
11208 +       .align 8
11209 +.LECIE1:
11210 +.LSFDE1:
11211 +       .long   .LEFDE1-.LASFDE1
11212 +.LASFDE1:
11213 +       .long   .LASFDE1-.Lframe1
11214 +       .long   .LFB2
11215 +       .long   .LFE2-.LFB2
11216 +       .uleb128 0x0
11217 +       .byte   0x4
11218 +       .long   .LCFI0-.LFB2
11219 +       .byte   0xe
11220 +       .uleb128 0x10
11221 +       .byte   0x86
11222 +       .uleb128 0x2
11223 +       .byte   0x4
11224 +       .long   .LCFI1-.LCFI0
11225 +       .byte   0xd
11226 +       .uleb128 0x6
11227 +       .align 8
11228 +.LEFDE1:
11229 +       .text
11230 +.Letext0:
11231 +       .section        .debug_loc,"",@progbits
11232 +.Ldebug_loc0:
11233 +.LLST0:
11234 +       .quad   .LFB2-.Ltext0
11235 +       .quad   .LCFI0-.Ltext0
11236 +       .value  0x2
11237 +       .byte   0x77
11238 +       .sleb128 8
11239 +       .quad   .LCFI0-.Ltext0
11240 +       .quad   .LCFI1-.Ltext0
11241 +       .value  0x2
11242 +       .byte   0x77
11243 +       .sleb128 16
11244 +       .quad   .LCFI1-.Ltext0
11245 +       .quad   .LFE2-.Ltext0
11246 +       .value  0x2
11247 +       .byte   0x76
11248 +       .sleb128 16
11249 +       .quad   0x0
11250 +       .quad   0x0
11251 +       .section        .debug_info
11252 +.Ldebug_relative:
11253 +       .long   .Ldebug_end - .Ldebug_start
11254 +.Ldebug_start:
11255 +       .value  0x2
11256 +       .long   .Ldebug_abbrev0
11257 +       .byte   0x8
11258 +       .uleb128 0x1
11259 +       .long   .LASF2
11260 +       .byte   0x1
11261 +       .long   .LASF3
11262 +       .long   .LASF4
11263 +       .quad   .Ltext0
11264 +       .quad   .Letext0
11265 +       .long   .Ldebug_line0
11266 +       .uleb128 0x2
11267 +       .byte   0x1
11268 +       .string "foo"
11269 +       .byte   0x1
11270 +       .byte   0x16
11271 +       .byte   0x1
11272 +       .quad   .LFB2
11273 +       .quad   .LFE2
11274 +       .long   .LLST0
11275 +       .long   .Ltype_int - .Ldebug_relative
11276 +       .uleb128 0x3
11277 +       .long   .LASF5
11278 +       .byte   0x1
11279 +       .byte   0x15
11280 +       .long   .Ltype_int - .Ldebug_relative
11281 +       .byte   0x2
11282 +       .byte   0x91
11283 +       .sleb128 -52
11284 +.Ltag_pointer:
11285 +       .uleb128 0x4
11286 +       .byte   0x8     /* DW_AT_byte_size */
11287 +       .long   .Ltag_array_type - .debug_info  /* DW_AT_type */
11288 +       .uleb128 0x5    /* Abbrev Number: 5 (DW_TAG_variable) */
11289 +       .long   .LASF0
11290 +       .byte   0x1
11291 +       .byte   0x18
11292 +#if 1
11293 +       .long   .Ltag_pointer - .debug_info
11294 +#else
11295 +       /* Debugging only: Skip the typedef indirection.  */
11296 +       .long   .Ltag_array_type - .debug_info
11297 +#endif
11298 +       /* DW_AT_location: DW_FORM_block1: start */
11299 +       .byte   0x3
11300 +       .byte   0x91
11301 +       .sleb128 -32
11302 +#if 0
11303 +       .byte   0x6     /* DW_OP_deref */
11304 +#else
11305 +       .byte   0x96    /* DW_OP_nop */
11306 +#endif
11307 +       /* DW_AT_location: DW_FORM_block1: end */
11308 +       .uleb128 0x6
11309 +       .string "i"
11310 +       .byte   0x1
11311 +       .byte   0x19
11312 +       .long   .Ltype_int - .Ldebug_relative
11313 +       .byte   0x2
11314 +       .byte   0x91
11315 +       .sleb128 -20
11316 +       .byte   0x0
11317 +.Ltype_int:
11318 +       .uleb128 0x7
11319 +       .byte   0x4
11320 +       .byte   0x5
11321 +       .string "int"
11322 +.Ltag_array_type:
11323 +       .uleb128 0x8    /* Abbrev Number: 8 (DW_TAG_array_type) */
11324 +       .long   .Ltype_char - .Ldebug_relative
11325 +       .long   .Ltype_ulong - .Ldebug_relative /* DW_AT_sibling: DW_FORM_ref4 */
11326 +1:     /* DW_AT_data_location: DW_FORM_block1: start */
11327 +       .byte   2f - 3f /* length */
11328 +3:
11329 +       .byte   0x97    /* DW_OP_push_object_address */
11330 +#if 1
11331 +       .byte   0x6     /* DW_OP_deref */
11332 +#else
11333 +       .byte   0x96    /* DW_OP_nop */
11334 +#endif
11335 +2:     /* DW_AT_data_location: DW_FORM_block1: end */
11336 +       .uleb128 0x9
11337 +       .long   .Ltype_char - .Ldebug_relative  /* DW_AT_type: DW_FORM_ref4 */
11338 +       .byte   0x3
11339 +       .byte   0x91
11340 +       .sleb128 -40
11341 +       .byte   0x6
11342 +       .byte   0x0
11343 +.Ltype_ulong:
11344 +       .uleb128 0xa
11345 +       .byte   0x8
11346 +       .byte   0x7
11347 +.Ltype_char:
11348 +       .uleb128 0xb
11349 +       .byte   0x1
11350 +       .byte   0x6
11351 +       .long   .LASF1
11352 +       .byte   0x0
11353 +.Ldebug_end:
11354 +       .section        .debug_abbrev
11355 +       .uleb128 0x1
11356 +       .uleb128 0x11
11357 +       .byte   0x1
11358 +       .uleb128 0x25
11359 +       .uleb128 0xe
11360 +       .uleb128 0x13
11361 +       .uleb128 0xb
11362 +       .uleb128 0x3
11363 +       .uleb128 0xe
11364 +       .uleb128 0x1b
11365 +       .uleb128 0xe
11366 +       .uleb128 0x11
11367 +       .uleb128 0x1
11368 +       .uleb128 0x12
11369 +       .uleb128 0x1
11370 +       .uleb128 0x10
11371 +       .uleb128 0x6
11372 +       .byte   0x0
11373 +       .byte   0x0
11374 +       .uleb128 0x2
11375 +       .uleb128 0x2e
11376 +       .byte   0x1
11377 +       .uleb128 0x3f
11378 +       .uleb128 0xc
11379 +       .uleb128 0x3
11380 +       .uleb128 0x8
11381 +       .uleb128 0x3a
11382 +       .uleb128 0xb
11383 +       .uleb128 0x3b
11384 +       .uleb128 0xb
11385 +       .uleb128 0x27
11386 +       .uleb128 0xc
11387 +       .uleb128 0x11
11388 +       .uleb128 0x1
11389 +       .uleb128 0x12
11390 +       .uleb128 0x1
11391 +       .uleb128 0x40
11392 +       .uleb128 0x6
11393 +       .uleb128 0x1
11394 +       .uleb128 0x13
11395 +       .byte   0x0
11396 +       .byte   0x0
11397 +       .uleb128 0x3
11398 +       .uleb128 0x5
11399 +       .byte   0x0
11400 +       .uleb128 0x3
11401 +       .uleb128 0xe
11402 +       .uleb128 0x3a
11403 +       .uleb128 0xb
11404 +       .uleb128 0x3b
11405 +       .uleb128 0xb
11406 +       .uleb128 0x49
11407 +       .uleb128 0x13
11408 +       .uleb128 0x2
11409 +       .uleb128 0xa
11410 +       .byte   0x0
11411 +       .byte   0x0
11412 +       .uleb128 0x4    /* .Ltag_pointer abbrev */
11413 +       .uleb128 0x0f   /* DW_TAG_pointer_type */
11414 +       .byte   0x0
11415 +       .uleb128 0x0b
11416 +       .uleb128 0xb
11417 +       .uleb128 0x49
11418 +       .uleb128 0x13
11419 +       .byte   0x0
11420 +       .byte   0x0
11421 +       .uleb128 0x5
11422 +       .uleb128 0x34
11423 +       .byte   0x0
11424 +       .uleb128 0x3
11425 +       .uleb128 0xe
11426 +       .uleb128 0x3a
11427 +       .uleb128 0xb
11428 +       .uleb128 0x3b
11429 +       .uleb128 0xb
11430 +       .uleb128 0x49
11431 +       .uleb128 0x13
11432 +       .uleb128 0x2
11433 +       .uleb128 0xa
11434 +       .byte   0x0
11435 +       .byte   0x0
11436 +       .uleb128 0x6
11437 +       .uleb128 0x34
11438 +       .byte   0x0
11439 +       .uleb128 0x3
11440 +       .uleb128 0x8
11441 +       .uleb128 0x3a
11442 +       .uleb128 0xb
11443 +       .uleb128 0x3b
11444 +       .uleb128 0xb
11445 +       .uleb128 0x49
11446 +       .uleb128 0x13
11447 +       .uleb128 0x2
11448 +       .uleb128 0xa
11449 +       .byte   0x0
11450 +       .byte   0x0
11451 +       .uleb128 0x7
11452 +       .uleb128 0x24
11453 +       .byte   0x0
11454 +       .uleb128 0xb
11455 +       .uleb128 0xb
11456 +       .uleb128 0x3e
11457 +       .uleb128 0xb
11458 +       .uleb128 0x3
11459 +       .uleb128 0x8
11460 +       .byte   0x0
11461 +       .byte   0x0
11462 +       .uleb128 0x8    /* Abbrev Number: 8 (DW_TAG_array_type) */
11463 +       .uleb128 0x1
11464 +       .byte   0x1
11465 +       .uleb128 0x49   /* DW_AT_type */
11466 +       .uleb128 0x13   /* DW_FORM_ref4 */
11467 +       .uleb128 0x1    /* DW_AT_sibling */
11468 +       .uleb128 0x13   /* DW_FORM_ref4 */
11469 +       .uleb128 0x50   /* DW_AT_data_location */
11470 +       .uleb128 0xa    /* DW_FORM_block1 */
11471 +       .byte   0x0
11472 +       .byte   0x0
11473 +       .uleb128 0x9
11474 +       .uleb128 0x21
11475 +       .byte   0x0
11476 +       .uleb128 0x49   /* DW_AT_type */
11477 +       .uleb128 0x13   /* DW_FORM_ref4 */
11478 +       .uleb128 0x2f
11479 +       .uleb128 0xa
11480 +       .byte   0x0
11481 +       .byte   0x0
11482 +       .uleb128 0xa
11483 +       .uleb128 0x24
11484 +       .byte   0x0
11485 +       .uleb128 0xb
11486 +       .uleb128 0xb
11487 +       .uleb128 0x3e
11488 +       .uleb128 0xb
11489 +       .byte   0x0
11490 +       .byte   0x0
11491 +       .uleb128 0xb
11492 +       .uleb128 0x24
11493 +       .byte   0x0
11494 +       .uleb128 0xb
11495 +       .uleb128 0xb
11496 +       .uleb128 0x3e
11497 +       .uleb128 0xb
11498 +       .uleb128 0x3
11499 +       .uleb128 0xe
11500 +       .byte   0x0
11501 +       .byte   0x0
11502 +       .byte   0x0
11503 +       .section        .debug_pubnames,"",@progbits
11504 +       .long   0x16
11505 +       .value  0x2
11506 +       .long   .Ldebug_info0
11507 +       .long   0xa8
11508 +       .long   0x2d
11509 +       .string "foo"
11510 +       .long   0x0
11511 +       .section        .debug_aranges,"",@progbits
11512 +       .long   0x2c
11513 +       .value  0x2
11514 +       .long   .Ldebug_info0
11515 +       .byte   0x8
11516 +       .byte   0x0
11517 +       .value  0x0
11518 +       .value  0x0
11519 +       .quad   .Ltext0
11520 +       .quad   .Letext0-.Ltext0
11521 +       .quad   0x0
11522 +       .quad   0x0
11523 +       .section        .debug_str,"MS",@progbits,1
11524 +.LASF0:
11525 +       .string "array"
11526 +.LASF5:
11527 +       .string "size"
11528 +.LASF3:
11529 +       .string "x86_64-vla-pointer.c"
11530 +.LASF6:
11531 +       .string "array_t"
11532 +.LASF1:
11533 +       .string "char"
11534 +.LASF4:
11535 +       .string "gdb.arch"
11536 +.LASF2:
11537 +       .string "GNU C 4.3.2 20081105 (Red Hat 4.3.2-7)"
11538 +       .ident  "GCC: (GNU) 4.3.2 20081105 (Red Hat 4.3.2-7)"
11539 +       .section        .note.GNU-stack,"",@progbits
11540 diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-pointer.c b/gdb/testsuite/gdb.arch/x86_64-vla-pointer.c
11541 new file mode 100644
11542 index 0000000..fe2c8f7
11543 --- /dev/null
11544 +++ b/gdb/testsuite/gdb.arch/x86_64-vla-pointer.c
11545 @@ -0,0 +1,43 @@
11546 +/* This testcase is part of GDB, the GNU debugger.
11547 +
11548 +   Copyright 2009 Free Software Foundation, Inc.
11549 +
11550 +   This program is free software; you can redistribute it and/or modify
11551 +   it under the terms of the GNU General Public License as published by
11552 +   the Free Software Foundation; either version 3 of the License, or
11553 +   (at your option) any later version.
11554 +
11555 +   This program is distributed in the hope that it will be useful,
11556 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
11557 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11558 +   GNU General Public License for more details.
11559 +
11560 +   You should have received a copy of the GNU General Public License
11561 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
11562 +
11563 +#if 0
11564 +
11565 +void
11566 +foo (int size)
11567 +{
11568 +  typedef char array_t[size];
11569 +  array_t array;
11570 +  int i;
11571 +
11572 +  for (i = 0; i < size; i++)
11573 +    array[i] = i;
11574 +
11575 +  array[0] = 0;        /* break-here */
11576 +}
11577 +
11578 +#else
11579 +
11580 +int
11581 +main (void)
11582 +{
11583 +  foo (26);
11584 +  foo (78);
11585 +  return 0;
11586 +}
11587 +
11588 +#endif
11589 diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-pointer.exp b/gdb/testsuite/gdb.arch/x86_64-vla-pointer.exp
11590 new file mode 100644
11591 index 0000000..d243cf1
11592 --- /dev/null
11593 +++ b/gdb/testsuite/gdb.arch/x86_64-vla-pointer.exp
11594 @@ -0,0 +1,66 @@
11595 +# Copyright 2009 Free Software Foundation, Inc.
11596 +
11597 +# This program is free software; you can redistribute it and/or modify
11598 +# it under the terms of the GNU General Public License as published by
11599 +# the Free Software Foundation; either version 3 of the License, or
11600 +# (at your option) any later version.
11601 +#
11602 +# This program is distributed in the hope that it will be useful,
11603 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
11604 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11605 +# GNU General Public License for more details.
11606 +#
11607 +# You should have received a copy of the GNU General Public License
11608 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
11609 +
11610 +if ![istarget "x86_64-*-*"] then {
11611 +    verbose "Skipping over gdb.arch/x86_64-vla-pointer.exp test made only for x86_64."
11612 +    return
11613 +}
11614 +
11615 +set testfile x86_64-vla-pointer
11616 +set srcasmfile ${testfile}-foo.S
11617 +set srcfile ${testfile}.c
11618 +set binfile ${objdir}/${subdir}/${testfile}
11619 +set binobjfile ${objdir}/${subdir}/${testfile}-foo.o
11620 +if  { [gdb_compile "${srcdir}/${subdir}/${srcasmfile}" "${binobjfile}" object {}] != "" } {
11621 +    untested "Couldn't compile test program"
11622 +    return -1
11623 +}
11624 +if  { [gdb_compile "${srcdir}/${subdir}/${srcfile} ${binobjfile}" "${binfile}" executable {debug}] != "" } {
11625 +    untested "Couldn't compile test program"
11626 +    return -1
11627 +}
11628 +
11629 +gdb_exit
11630 +gdb_start
11631 +gdb_reinitialize_dir $srcdir/$subdir
11632 +gdb_load ${binfile}
11633 +
11634 +if ![runto_main] {
11635 +    untested x86_64-vla-pointer
11636 +    return -1
11637 +}
11638 +
11639 +gdb_breakpoint "break_here"
11640 +
11641 +gdb_continue_to_breakpoint "break_here"
11642 +
11643 +gdb_test "whatis array" "type = char \\(\\*\\)\\\[variable\\\]" "first: whatis array"
11644 +gdb_test "ptype array" "type = char \\(\\*\\)\\\[26\\\]" "first: ptype array"
11645 +
11646 +gdb_test "whatis *array" "type = char \\\[26\\\]" "first: whatis *array"
11647 +gdb_test "ptype *array" "type = char \\\[26\\\]" "first: ptype *array"
11648 +
11649 +gdb_test "p (*array)\[1\]" "\\$\[0-9\] = 1 '\\\\001'"
11650 +gdb_test "p (*array)\[2\]" "\\$\[0-9\] = 2 '\\\\002'"
11651 +gdb_test "p (*array)\[3\]" "\\$\[0-9\] = 3 '\\\\003'"
11652 +gdb_test "p (*array)\[4\]" "\\$\[0-9\] = 4 '\\\\004'"
11653 +
11654 +gdb_continue_to_breakpoint "break_here"
11655 +
11656 +gdb_test "whatis array" "type = char \\(\\*\\)\\\[variable\\\]" "second: whatis array"
11657 +gdb_test "ptype array" "type = char \\(\\*\\)\\\[78\\\]" "second: ptype array"
11658 +
11659 +gdb_test "whatis *array" "type = char \\\[78\\\]" "second: whatis *array"
11660 +gdb_test "ptype *array" "type = char \\\[78\\\]" "second: ptype *array"
11661 diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-typedef-foo.S b/gdb/testsuite/gdb.arch/x86_64-vla-typedef-foo.S
11662 new file mode 100644
11663 index 0000000..66f7a39
11664 --- /dev/null
11665 +++ b/gdb/testsuite/gdb.arch/x86_64-vla-typedef-foo.S
11666 @@ -0,0 +1,455 @@
11667 +       .file   "x86_64-vla-typedef.c"
11668 +       .section        .debug_abbrev,"",@progbits
11669 +.Ldebug_abbrev0:
11670 +       .section        .debug_info,"",@progbits
11671 +.Ldebug_info0:
11672 +       .section        .debug_line,"",@progbits
11673 +.Ldebug_line0:
11674 +       .text
11675 +.Ltext0:
11676 +.globl foo
11677 +       .type   foo, @function
11678 +foo:
11679 +.LFB2:
11680 +       .file 1 "x86_64-vla-typedef.c"
11681 +       .loc 1 22 0
11682 +       pushq   %rbp
11683 +.LCFI0:
11684 +       movq    %rsp, %rbp
11685 +.LCFI1:
11686 +       subq    $64, %rsp
11687 +.LCFI2:
11688 +       movl    %edi, -36(%rbp)
11689 +       .loc 1 22 0
11690 +       movq    %rsp, %rax
11691 +       movq    %rax, -48(%rbp)
11692 +       .loc 1 23 0
11693 +       movl    -36(%rbp), %edx
11694 +       movslq  %edx,%rax
11695 +       subq    $1, %rax
11696 +       movq    %rax, -24(%rbp)
11697 +       .loc 1 24 0
11698 +       movslq  %edx,%rax
11699 +       addq    $15, %rax
11700 +       addq    $15, %rax
11701 +       shrq    $4, %rax
11702 +       salq    $4, %rax
11703 +       subq    %rax, %rsp
11704 +       movq    %rsp, -56(%rbp)
11705 +       movq    -56(%rbp), %rax
11706 +       addq    $15, %rax
11707 +       shrq    $4, %rax
11708 +       salq    $4, %rax
11709 +       movq    %rax, -56(%rbp)
11710 +       movq    -56(%rbp), %rax
11711 +       movq    %rax, -16(%rbp)
11712 +       .loc 1 27 0
11713 +       movl    $0, -4(%rbp)
11714 +       jmp     .L2
11715 +.L3:
11716 +       .loc 1 28 0
11717 +       movl    -4(%rbp), %esi
11718 +       movl    -4(%rbp), %eax
11719 +       movl    %eax, %ecx
11720 +       movq    -16(%rbp), %rdx
11721 +       movslq  %esi,%rax
11722 +       movb    %cl, (%rdx,%rax)
11723 +       .loc 1 27 0
11724 +       addl    $1, -4(%rbp)
11725 +.L2:
11726 +       movl    -4(%rbp), %eax
11727 +       cmpl    -36(%rbp), %eax
11728 +       jl      .L3
11729 +       .loc 1 30 0
11730 +       .globl  break_here
11731 +break_here:
11732 +       movq    -16(%rbp), %rax
11733 +       movb    $0, (%rax)
11734 +       movq    -48(%rbp), %rsp
11735 +       .loc 1 31 0
11736 +       leave
11737 +       ret
11738 +.LFE2:
11739 +       .size   foo, .-foo
11740 +       .section        .debug_frame,"",@progbits
11741 +.Lframe0:
11742 +       .long   .LECIE0-.LSCIE0
11743 +.LSCIE0:
11744 +       .long   0xffffffff
11745 +       .byte   0x1
11746 +       .string ""
11747 +       .uleb128 0x1
11748 +       .sleb128 -8
11749 +       .byte   0x10
11750 +       .byte   0xc
11751 +       .uleb128 0x7
11752 +       .uleb128 0x8
11753 +       .byte   0x90
11754 +       .uleb128 0x1
11755 +       .align 8
11756 +.LECIE0:
11757 +.LSFDE0:
11758 +       .long   .LEFDE0-.LASFDE0
11759 +.LASFDE0:
11760 +       .long   .Lframe0
11761 +       .quad   .LFB2
11762 +       .quad   .LFE2-.LFB2
11763 +       .byte   0x4
11764 +       .long   .LCFI0-.LFB2
11765 +       .byte   0xe
11766 +       .uleb128 0x10
11767 +       .byte   0x86
11768 +       .uleb128 0x2
11769 +       .byte   0x4
11770 +       .long   .LCFI1-.LCFI0
11771 +       .byte   0xd
11772 +       .uleb128 0x6
11773 +       .align 8
11774 +.LEFDE0:
11775 +       .section        .eh_frame,"a",@progbits
11776 +.Lframe1:
11777 +       .long   .LECIE1-.LSCIE1
11778 +.LSCIE1:
11779 +       .long   0x0
11780 +       .byte   0x1
11781 +       .string "zR"
11782 +       .uleb128 0x1
11783 +       .sleb128 -8
11784 +       .byte   0x10
11785 +       .uleb128 0x1
11786 +       .byte   0x3
11787 +       .byte   0xc
11788 +       .uleb128 0x7
11789 +       .uleb128 0x8
11790 +       .byte   0x90
11791 +       .uleb128 0x1
11792 +       .align 8
11793 +.LECIE1:
11794 +.LSFDE1:
11795 +       .long   .LEFDE1-.LASFDE1
11796 +.LASFDE1:
11797 +       .long   .LASFDE1-.Lframe1
11798 +       .long   .LFB2
11799 +       .long   .LFE2-.LFB2
11800 +       .uleb128 0x0
11801 +       .byte   0x4
11802 +       .long   .LCFI0-.LFB2
11803 +       .byte   0xe
11804 +       .uleb128 0x10
11805 +       .byte   0x86
11806 +       .uleb128 0x2
11807 +       .byte   0x4
11808 +       .long   .LCFI1-.LCFI0
11809 +       .byte   0xd
11810 +       .uleb128 0x6
11811 +       .align 8
11812 +.LEFDE1:
11813 +       .text
11814 +.Letext0:
11815 +       .section        .debug_loc,"",@progbits
11816 +.Ldebug_loc0:
11817 +.LLST0:
11818 +       .quad   .LFB2-.Ltext0
11819 +       .quad   .LCFI0-.Ltext0
11820 +       .value  0x2
11821 +       .byte   0x77
11822 +       .sleb128 8
11823 +       .quad   .LCFI0-.Ltext0
11824 +       .quad   .LCFI1-.Ltext0
11825 +       .value  0x2
11826 +       .byte   0x77
11827 +       .sleb128 16
11828 +       .quad   .LCFI1-.Ltext0
11829 +       .quad   .LFE2-.Ltext0
11830 +       .value  0x2
11831 +       .byte   0x76
11832 +       .sleb128 16
11833 +       .quad   0x0
11834 +       .quad   0x0
11835 +       .section        .debug_info
11836 +       .long   .Ldebug_end - .Ldebug_start
11837 +.Ldebug_start:
11838 +       .value  0x2
11839 +       .long   .Ldebug_abbrev0
11840 +       .byte   0x8
11841 +       .uleb128 0x1
11842 +       .long   .LASF2
11843 +       .byte   0x1
11844 +       .long   .LASF3
11845 +       .long   .LASF4
11846 +       .quad   .Ltext0
11847 +       .quad   .Letext0
11848 +       .long   .Ldebug_line0
11849 +       .uleb128 0x2
11850 +       .byte   0x1
11851 +       .string "foo"
11852 +       .byte   0x1
11853 +       .byte   0x16
11854 +       .byte   0x1
11855 +       .quad   .LFB2
11856 +       .quad   .LFE2
11857 +       .long   .LLST0
11858 +       .long   0x83
11859 +       .uleb128 0x3
11860 +       .long   .LASF5
11861 +       .byte   0x1
11862 +       .byte   0x15
11863 +       .long   0x83
11864 +       .byte   0x2
11865 +       .byte   0x91
11866 +       .sleb128 -52
11867 +.Ltag_typedef:
11868 +       .uleb128 0x4
11869 +       .long   .LASF6
11870 +       .byte   0x1
11871 +       .byte   0x17
11872 +       .long   .Ltag_array_type - .debug_info
11873 +       .uleb128 0x5    /* Abbrev Number: 5 (DW_TAG_variable) */
11874 +       .long   .LASF0
11875 +       .byte   0x1
11876 +       .byte   0x18
11877 +#if 1
11878 +       .long   .Ltag_typedef - .debug_info
11879 +#else
11880 +       /* Debugging only: Skip the typedef indirection.  */
11881 +       .long   .Ltag_array_type - .debug_info
11882 +#endif
11883 +       /* DW_AT_location: DW_FORM_block1: start */
11884 +       .byte   0x3
11885 +       .byte   0x91
11886 +       .sleb128 -32
11887 +#if 0
11888 +       .byte   0x6     /* DW_OP_deref */
11889 +#else
11890 +       .byte   0x96    /* DW_OP_nop */
11891 +#endif
11892 +       /* DW_AT_location: DW_FORM_block1: end */
11893 +       .uleb128 0x6
11894 +       .string "i"
11895 +       .byte   0x1
11896 +       .byte   0x19
11897 +       .long   0x83
11898 +       .byte   0x2
11899 +       .byte   0x91
11900 +       .sleb128 -20
11901 +       .byte   0x0
11902 +       .uleb128 0x7
11903 +       .byte   0x4
11904 +       .byte   0x5
11905 +       .string "int"
11906 +.Ltag_array_type:
11907 +       .uleb128 0x8    /* Abbrev Number: 8 (DW_TAG_array_type) */
11908 +       .long   0xa0 + (2f - 1f)        /* DW_AT_type: DW_FORM_ref4 */
11909 +       .long   0x9d + (2f - 1f)        /* DW_AT_sibling: DW_FORM_ref4 */
11910 +1:     /* DW_AT_data_location: DW_FORM_block1: start */
11911 +       .byte   2f - 3f /* length */
11912 +3:
11913 +       .byte   0x97    /* DW_OP_push_object_address */
11914 +       .byte   0x6     /* DW_OP_deref */
11915 +2:     /* DW_AT_data_location: DW_FORM_block1: end */
11916 +       .uleb128 0x9
11917 +       .long   0x9d + (2b - 1b)        /* DW_AT_type: DW_FORM_ref4 */
11918 +       .byte   0x3
11919 +       .byte   0x91
11920 +       .sleb128 -40
11921 +       .byte   0x6
11922 +       .byte   0x0
11923 +       .uleb128 0xa
11924 +       .byte   0x8
11925 +       .byte   0x7
11926 +       .uleb128 0xb
11927 +       .byte   0x1
11928 +       .byte   0x6
11929 +       .long   .LASF1
11930 +       .byte   0x0
11931 +.Ldebug_end:
11932 +       .section        .debug_abbrev
11933 +       .uleb128 0x1
11934 +       .uleb128 0x11
11935 +       .byte   0x1
11936 +       .uleb128 0x25
11937 +       .uleb128 0xe
11938 +       .uleb128 0x13
11939 +       .uleb128 0xb
11940 +       .uleb128 0x3
11941 +       .uleb128 0xe
11942 +       .uleb128 0x1b
11943 +       .uleb128 0xe
11944 +       .uleb128 0x11
11945 +       .uleb128 0x1
11946 +       .uleb128 0x12
11947 +       .uleb128 0x1
11948 +       .uleb128 0x10
11949 +       .uleb128 0x6
11950 +       .byte   0x0
11951 +       .byte   0x0
11952 +       .uleb128 0x2
11953 +       .uleb128 0x2e
11954 +       .byte   0x1
11955 +       .uleb128 0x3f
11956 +       .uleb128 0xc
11957 +       .uleb128 0x3
11958 +       .uleb128 0x8
11959 +       .uleb128 0x3a
11960 +       .uleb128 0xb
11961 +       .uleb128 0x3b
11962 +       .uleb128 0xb
11963 +       .uleb128 0x27
11964 +       .uleb128 0xc
11965 +       .uleb128 0x11
11966 +       .uleb128 0x1
11967 +       .uleb128 0x12
11968 +       .uleb128 0x1
11969 +       .uleb128 0x40
11970 +       .uleb128 0x6
11971 +       .uleb128 0x1
11972 +       .uleb128 0x13
11973 +       .byte   0x0
11974 +       .byte   0x0
11975 +       .uleb128 0x3
11976 +       .uleb128 0x5
11977 +       .byte   0x0
11978 +       .uleb128 0x3
11979 +       .uleb128 0xe
11980 +       .uleb128 0x3a
11981 +       .uleb128 0xb
11982 +       .uleb128 0x3b
11983 +       .uleb128 0xb
11984 +       .uleb128 0x49
11985 +       .uleb128 0x13
11986 +       .uleb128 0x2
11987 +       .uleb128 0xa
11988 +       .byte   0x0
11989 +       .byte   0x0
11990 +       .uleb128 0x4
11991 +       .uleb128 0x16
11992 +       .byte   0x0
11993 +       .uleb128 0x3
11994 +       .uleb128 0xe
11995 +       .uleb128 0x3a
11996 +       .uleb128 0xb
11997 +       .uleb128 0x3b
11998 +       .uleb128 0xb
11999 +       .uleb128 0x49
12000 +       .uleb128 0x13
12001 +       .byte   0x0
12002 +       .byte   0x0
12003 +       .uleb128 0x5
12004 +       .uleb128 0x34
12005 +       .byte   0x0
12006 +       .uleb128 0x3
12007 +       .uleb128 0xe
12008 +       .uleb128 0x3a
12009 +       .uleb128 0xb
12010 +       .uleb128 0x3b
12011 +       .uleb128 0xb
12012 +       .uleb128 0x49
12013 +       .uleb128 0x13
12014 +       .uleb128 0x2
12015 +       .uleb128 0xa
12016 +       .byte   0x0
12017 +       .byte   0x0
12018 +       .uleb128 0x6
12019 +       .uleb128 0x34
12020 +       .byte   0x0
12021 +       .uleb128 0x3
12022 +       .uleb128 0x8
12023 +       .uleb128 0x3a
12024 +       .uleb128 0xb
12025 +       .uleb128 0x3b
12026 +       .uleb128 0xb
12027 +       .uleb128 0x49
12028 +       .uleb128 0x13
12029 +       .uleb128 0x2
12030 +       .uleb128 0xa
12031 +       .byte   0x0
12032 +       .byte   0x0
12033 +       .uleb128 0x7
12034 +       .uleb128 0x24
12035 +       .byte   0x0
12036 +       .uleb128 0xb
12037 +       .uleb128 0xb
12038 +       .uleb128 0x3e
12039 +       .uleb128 0xb
12040 +       .uleb128 0x3
12041 +       .uleb128 0x8
12042 +       .byte   0x0
12043 +       .byte   0x0
12044 +       .uleb128 0x8    /* Abbrev Number: 8 (DW_TAG_array_type) */
12045 +       .uleb128 0x1
12046 +       .byte   0x1
12047 +       .uleb128 0x49   /* DW_AT_type */
12048 +       .uleb128 0x13   /* DW_FORM_ref4 */
12049 +       .uleb128 0x1    /* DW_AT_sibling */
12050 +       .uleb128 0x13   /* DW_FORM_ref4 */
12051 +       .uleb128 0x50   /* DW_AT_data_location */
12052 +       .uleb128 0xa    /* DW_FORM_block1 */
12053 +       .byte   0x0
12054 +       .byte   0x0
12055 +       .uleb128 0x9
12056 +       .uleb128 0x21
12057 +       .byte   0x0
12058 +       .uleb128 0x49   /* DW_AT_type */
12059 +       .uleb128 0x13   /* DW_FORM_ref4 */
12060 +       .uleb128 0x2f
12061 +       .uleb128 0xa
12062 +       .byte   0x0
12063 +       .byte   0x0
12064 +       .uleb128 0xa
12065 +       .uleb128 0x24
12066 +       .byte   0x0
12067 +       .uleb128 0xb
12068 +       .uleb128 0xb
12069 +       .uleb128 0x3e
12070 +       .uleb128 0xb
12071 +       .byte   0x0
12072 +       .byte   0x0
12073 +       .uleb128 0xb
12074 +       .uleb128 0x24
12075 +       .byte   0x0
12076 +       .uleb128 0xb
12077 +       .uleb128 0xb
12078 +       .uleb128 0x3e
12079 +       .uleb128 0xb
12080 +       .uleb128 0x3
12081 +       .uleb128 0xe
12082 +       .byte   0x0
12083 +       .byte   0x0
12084 +       .byte   0x0
12085 +       .section        .debug_pubnames,"",@progbits
12086 +       .long   0x16
12087 +       .value  0x2
12088 +       .long   .Ldebug_info0
12089 +       .long   0xa8
12090 +       .long   0x2d
12091 +       .string "foo"
12092 +       .long   0x0
12093 +       .section        .debug_aranges,"",@progbits
12094 +       .long   0x2c
12095 +       .value  0x2
12096 +       .long   .Ldebug_info0
12097 +       .byte   0x8
12098 +       .byte   0x0
12099 +       .value  0x0
12100 +       .value  0x0
12101 +       .quad   .Ltext0
12102 +       .quad   .Letext0-.Ltext0
12103 +       .quad   0x0
12104 +       .quad   0x0
12105 +       .section        .debug_str,"MS",@progbits,1
12106 +.LASF0:
12107 +       .string "array"
12108 +.LASF5:
12109 +       .string "size"
12110 +.LASF3:
12111 +       .string "x86_64-vla-typedef.c"
12112 +.LASF6:
12113 +       .string "array_t"
12114 +.LASF1:
12115 +       .string "char"
12116 +.LASF4:
12117 +       .string "gdb.arch"
12118 +.LASF2:
12119 +       .string "GNU C 4.3.2 20081105 (Red Hat 4.3.2-7)"
12120 +       .ident  "GCC: (GNU) 4.3.2 20081105 (Red Hat 4.3.2-7)"
12121 +       .section        .note.GNU-stack,"",@progbits
12122 diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-typedef.c b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.c
12123 new file mode 100644
12124 index 0000000..b809c4e
12125 --- /dev/null
12126 +++ b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.c
12127 @@ -0,0 +1,43 @@
12128 +/* This testcase is part of GDB, the GNU debugger.
12129 +
12130 +   Copyright 2008 Free Software Foundation, Inc.
12131 +
12132 +   This program is free software; you can redistribute it and/or modify
12133 +   it under the terms of the GNU General Public License as published by
12134 +   the Free Software Foundation; either version 3 of the License, or
12135 +   (at your option) any later version.
12136 +
12137 +   This program is distributed in the hope that it will be useful,
12138 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
12139 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12140 +   GNU General Public License for more details.
12141 +
12142 +   You should have received a copy of the GNU General Public License
12143 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
12144 +
12145 +#if 0
12146 +
12147 +void
12148 +foo (int size)
12149 +{
12150 +  typedef char array_t[size];
12151 +  array_t array;
12152 +  int i;
12153 +
12154 +  for (i = 0; i < size; i++)
12155 +    array[i] = i;
12156 +
12157 +  array[0] = 0;        /* break-here */
12158 +}
12159 +
12160 +#else
12161 +
12162 +int
12163 +main (void)
12164 +{
12165 +  foo (26);
12166 +  foo (78);
12167 +  return 0;
12168 +}
12169 +
12170 +#endif
12171 diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp
12172 new file mode 100644
12173 index 0000000..b05411e
12174 --- /dev/null
12175 +++ b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp
12176 @@ -0,0 +1,64 @@
12177 +# Copyright 2009 Free Software Foundation, Inc.
12178 +
12179 +# This program is free software; you can redistribute it and/or modify
12180 +# it under the terms of the GNU General Public License as published by
12181 +# the Free Software Foundation; either version 3 of the License, or
12182 +# (at your option) any later version.
12183 +#
12184 +# This program is distributed in the hope that it will be useful,
12185 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12186 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12187 +# GNU General Public License for more details.
12188 +#
12189 +# You should have received a copy of the GNU General Public License
12190 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
12191 +
12192 +# Test DW_AT_data_location accessed through DW_TAG_typedef intermediate.
12193 +
12194 +if ![istarget "x86_64-*-*"] then {
12195 +    verbose "Skipping over gdb.arch/x86_64-vla-typedef.exp test made only for x86_64."
12196 +    return
12197 +}
12198 +
12199 +set testfile x86_64-vla-typedef
12200 +set srcasmfile ${testfile}-foo.S
12201 +set srcfile ${testfile}.c
12202 +set binfile ${objdir}/${subdir}/${testfile}
12203 +set binobjfile ${objdir}/${subdir}/${testfile}-foo.o
12204 +if  { [gdb_compile "${srcdir}/${subdir}/${srcasmfile}" "${binobjfile}" object {}] != "" } {
12205 +    untested "Couldn't compile test program"
12206 +    return -1
12207 +}
12208 +if  { [gdb_compile "${srcdir}/${subdir}/${srcfile} ${binobjfile}" "${binfile}" executable {debug}] != "" } {
12209 +    untested "Couldn't compile test program"
12210 +    return -1
12211 +}
12212 +
12213 +gdb_exit
12214 +gdb_start
12215 +gdb_reinitialize_dir $srcdir/$subdir
12216 +gdb_load ${binfile}
12217 +
12218 +if ![runto_main] {
12219 +    untested x86_64-vla-typedef
12220 +    return -1
12221 +}
12222 +
12223 +gdb_breakpoint "break_here"
12224 +
12225 +gdb_continue_to_breakpoint "break_here"
12226 +
12227 +gdb_test "whatis array" "type = array_t" "first: whatis array"
12228 +
12229 +gdb_test "ptype array" "type = char \\\[26\\\]" "first: ptype array"
12230 +
12231 +gdb_test "p array\[1\]" "\\$\[0-9\] = 1 '\\\\001'"
12232 +gdb_test "p array\[2\]" "\\$\[0-9\] = 2 '\\\\002'"
12233 +gdb_test "p array\[3\]" "\\$\[0-9\] = 3 '\\\\003'"
12234 +gdb_test "p array\[4\]" "\\$\[0-9\] = 4 '\\\\004'"
12235 +
12236 +gdb_continue_to_breakpoint "break_here"
12237 +
12238 +gdb_test "whatis array" "type = array_t" "second: whatis array"
12239 +
12240 +gdb_test "ptype array" "type = char \\\[78\\\]" "second: ptype array"
12241 diff --git a/gdb/testsuite/gdb.base/arrayidx.c b/gdb/testsuite/gdb.base/arrayidx.c
12242 index ecc3289..f79ad40 100644
12243 --- a/gdb/testsuite/gdb.base/arrayidx.c
12244 +++ b/gdb/testsuite/gdb.base/arrayidx.c
12245 @@ -17,6 +17,13 @@
12246  
12247  int array[] = {1, 2, 3, 4};
12248  
12249 +#ifdef __GNUC__
12250 +struct
12251 +  {
12252 +    int a[0];
12253 +  } unbound;
12254 +#endif
12255 +
12256  int
12257  main (void)
12258  {
12259 diff --git a/gdb/testsuite/gdb.base/arrayidx.exp b/gdb/testsuite/gdb.base/arrayidx.exp
12260 index 3a33618..f2e11dd 100644
12261 --- a/gdb/testsuite/gdb.base/arrayidx.exp
12262 +++ b/gdb/testsuite/gdb.base/arrayidx.exp
12263 @@ -57,4 +57,12 @@ gdb_test "print array" \
12264           "\\{\\\[0\\\] = 1, \\\[1\\\] = 2, \\\[2\\\] = 3, \\\[3\\\] = 4\\}" \
12265           "Print array with array-indexes on"
12266  
12267 -
12268 +set test "p unbound.a == &unbound.a\[0\]"
12269 +gdb_test_multiple $test $test {
12270 +    -re " = 1\r\n$gdb_prompt $" {
12271 +       pass $test
12272 +    }
12273 +    -re "No symbol \"unbound\" in current context.\r\n$gdb_prompt $" {
12274 +       unsupported "$test (no GCC)"
12275 +    }
12276 +}
12277 diff --git a/gdb/testsuite/gdb.base/gnu-ifunc-lib.c b/gdb/testsuite/gdb.base/gnu-ifunc-lib.c
12278 new file mode 100644
12279 index 0000000..680530a
12280 --- /dev/null
12281 +++ b/gdb/testsuite/gdb.base/gnu-ifunc-lib.c
12282 @@ -0,0 +1,33 @@
12283 +/* This testcase is part of GDB, the GNU debugger.
12284 +
12285 +   Copyright 2009, 2010 Free Software Foundation, Inc.
12286 +
12287 +   This program is free software; you can redistribute it and/or modify
12288 +   it under the terms of the GNU General Public License as published by
12289 +   the Free Software Foundation; either version 3 of the License, or
12290 +   (at your option) any later version.
12291 +
12292 +   This program is distributed in the hope that it will be useful,
12293 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
12294 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12295 +   GNU General Public License for more details.
12296 +
12297 +   You should have received a copy of the GNU General Public License
12298 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
12299 +
12300 +extern volatile int gnu_ifunc_initialized;
12301 +extern int init_stub (int arg);
12302 +extern int final (int arg);
12303 +
12304 +typedef int (*final_t) (int arg);
12305 +
12306 +asm (".type gnu_ifunc, @gnu_indirect_function");
12307 +
12308 +final_t
12309 +gnu_ifunc (void)
12310 +{
12311 +  if (! gnu_ifunc_initialized)
12312 +    return init_stub;
12313 +  else
12314 +    return final;
12315 +}
12316 diff --git a/gdb/testsuite/gdb.base/gnu-ifunc.c b/gdb/testsuite/gdb.base/gnu-ifunc.c
12317 new file mode 100644
12318 index 0000000..106271f
12319 --- /dev/null
12320 +++ b/gdb/testsuite/gdb.base/gnu-ifunc.c
12321 @@ -0,0 +1,61 @@
12322 +/* This testcase is part of GDB, the GNU debugger.
12323 +
12324 +   Copyright 2009, 2010 Free Software Foundation, Inc.
12325 +
12326 +   This program is free software; you can redistribute it and/or modify
12327 +   it under the terms of the GNU General Public License as published by
12328 +   the Free Software Foundation; either version 3 of the License, or
12329 +   (at your option) any later version.
12330 +
12331 +   This program is distributed in the hope that it will be useful,
12332 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
12333 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12334 +   GNU General Public License for more details.
12335 +
12336 +   You should have received a copy of the GNU General Public License
12337 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
12338 +
12339 +#include <assert.h>
12340 +
12341 +int
12342 +init_stub (int arg)
12343 +{
12344 +  return 0;
12345 +}
12346 +
12347 +int
12348 +final (int arg)
12349 +{
12350 +  return arg + 1;
12351 +}
12352 +
12353 +/* Make differentiation of how the gnu_ifunc call resolves before and after
12354 +   calling gnu_ifunc_pre.  This ensures the resolved function address is not
12355 +   being cached anywhere for the debugging purposes.  */
12356 +
12357 +volatile int gnu_ifunc_initialized;
12358 +
12359 +static void
12360 +gnu_ifunc_pre (void)
12361 +{
12362 +  assert (!gnu_ifunc_initialized);
12363 +
12364 +  gnu_ifunc_initialized = 1;
12365 +}
12366 +
12367 +extern int gnu_ifunc (int arg);
12368 +
12369 +int
12370 +main (void)
12371 +{
12372 +  int i;
12373 +
12374 +  gnu_ifunc_pre ();
12375 +  
12376 +  i = gnu_ifunc (1);   /* break-at-call */
12377 +  assert (i == 2);
12378 +
12379 +  gnu_ifunc (2);       /* break-at-nextcall */
12380 +
12381 +  return 0;    /* break-at-exit */
12382 +}
12383 diff --git a/gdb/testsuite/gdb.base/gnu-ifunc.exp b/gdb/testsuite/gdb.base/gnu-ifunc.exp
12384 new file mode 100644
12385 index 0000000..8ecf558
12386 --- /dev/null
12387 +++ b/gdb/testsuite/gdb.base/gnu-ifunc.exp
12388 @@ -0,0 +1,110 @@
12389 +# Copyright (C) 2009, 2010 Free Software Foundation, Inc.
12390 +
12391 +# This program is free software; you can redistribute it and/or modify
12392 +# it under the terms of the GNU General Public License as published by
12393 +# the Free Software Foundation; either version 3 of the License, or
12394 +# (at your option) any later version.
12395 +#
12396 +# This program is distributed in the hope that it will be useful,
12397 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12398 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12399 +# GNU General Public License for more details.
12400 +#
12401 +# You should have received a copy of the GNU General Public License
12402 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
12403 +
12404 +if {[skip_shlib_tests]} {
12405 +    return 0
12406 +}
12407 +
12408 +set testfile "gnu-ifunc"
12409 +set srcfile ${testfile}.c
12410 +set binfile ${objdir}/${subdir}/${testfile}
12411 +
12412 +set libfile "${testfile}-lib"
12413 +set libsrc ${libfile}.c
12414 +set lib_so ${objdir}/${subdir}/${libfile}.so
12415 +
12416 +# We need DWARF for the "final" function as we "step" into the function and GDB
12417 +# would step-over the "final" function if there would be no line number debug
12418 +# information (DWARF) available.
12419 +#
12420 +# We must not have DWARF for the "gnu_ifunc" function as DWARF has no way to
12421 +# express the gnu-ifunc type and it would be considered as a regular function
12422 +# due to DWARF by GDB.  In ELF gnu-ifunc is expressed by the STT_GNU_IFUNC type.
12423 +#
12424 +# Both functions need to be in the same shared library file but
12425 +# gdb_compile_shlib has no way to specify source-specific compilation options.
12426 +#
12427 +# Therefore $libfile contains only the gnu-ifunc function with no DWARF
12428 +# referencing all the other parts from the main executable with DWARF.
12429 +
12430 +set lib_opts {}
12431 +set exec_opts [list debug shlib=$lib_so]
12432 +
12433 +if [get_compiler_info ${binfile}] {
12434 +    return -1
12435 +}
12436 +
12437 +if { [gdb_compile_shlib ${srcdir}/${subdir}/$libsrc $lib_so $lib_opts] != ""
12438 +     || [gdb_compile ${srcdir}/${subdir}/$srcfile $binfile executable $exec_opts] != ""} {
12439 +    untested "Could not compile either $libsrc or $srcfile."
12440 +    return -1
12441 +}
12442 +
12443 +# Start with a fresh gdb.
12444 +
12445 +clean_restart $testfile
12446 +gdb_load_shlibs ${lib_so}
12447 +
12448 +if ![runto_main] then {
12449 +    fail "Can't run to main"
12450 +    return 1;
12451 +}
12452 +
12453 +# The "if" condition is artifical to test regression of a former patch.
12454 +gdb_breakpoint "[gdb_get_line_number "break-at-nextcall"] if i && gnu_ifunc (i) != 42"
12455 +
12456 +gdb_breakpoint [gdb_get_line_number "break-at-call"]
12457 +gdb_continue_to_breakpoint "break-at-call" ".*break-at-call.*"
12458 +
12459 +# Test GDB will automatically indirect the call.
12460 +
12461 +gdb_test "p gnu_ifunc (3)" " = 4"
12462 +
12463 +# Test GDB will skip the gnu_ifunc resolver on first call.
12464 +
12465 +gdb_test "step" "\r\nfinal .*"
12466 +
12467 +# Test GDB will not break before the final chosen implementation.
12468 +
12469 +# Also test a former patch regression:
12470 +# Continuing.
12471 +# Error in testing breakpoint condition:
12472 +# Attempt to take address of value not located in memory.
12473 +# 
12474 +# Breakpoint 2, main () at ./gdb.base/gnu-ifunc.c:33
12475 +
12476 +gdb_test "continue" "Continuing.\r\n\r\nBreakpoint .* (at|in) .*break-at-nextcall.*" \
12477 +        "continue to break-at-nextcall"
12478 +
12479 +gdb_breakpoint "gnu_ifunc"
12480 +
12481 +gdb_continue_to_breakpoint "nextcall gnu_ifunc"
12482 +
12483 +gdb_test "frame" "#0 +(0x\[0-9a-f\]+ in +)?final \\(.*" "nextcall gnu_ifunc skipped"
12484 +
12485 +
12486 +# Check any commands not doing an inferior call still compute with address of
12487 +# the gnu-ifunc resolver.
12488 +
12489 +gdb_test "p gnu_ifunc" " = {<text gnu-indirect-function variable, no debug info>} 0x\[0-9a-f\]+ <gnu_ifunc>" "p gnu_ifunc executing"
12490 +gdb_test "info sym gnu_ifunc" "gnu_ifunc in section .*" "info sym gnu_ifunc executing"
12491 +
12492 +set test "info addr gnu_ifunc"
12493 +gdb_test_multiple $test $test {
12494 +    -re "Symbol \"gnu_ifunc\" is at (0x\[0-9a-f\]+) in .*$gdb_prompt $" {
12495 +       pass $test
12496 +    }
12497 +}
12498 +gdb_test "info sym $expect_out(1,string)" "gnu_ifunc in section .*" "info sym <gnu_ifunc-address>"
12499 diff --git a/gdb/testsuite/gdb.base/internal-var-field-address.c b/gdb/testsuite/gdb.base/internal-var-field-address.c
12500 new file mode 100644
12501 index 0000000..eeb7b85
12502 --- /dev/null
12503 +++ b/gdb/testsuite/gdb.base/internal-var-field-address.c
12504 @@ -0,0 +1,20 @@
12505 +/* This testcase is part of GDB, the GNU debugger.
12506 +
12507 +   Copyright 2009 Free Software Foundation, Inc.
12508 +
12509 +   This program is free software; you can redistribute it and/or modify
12510 +   it under the terms of the GNU General Public License as published by
12511 +   the Free Software Foundation; either version 3 of the License, or
12512 +   (at your option) any later version.
12513 +
12514 +   This program is distributed in the hope that it will be useful,
12515 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
12516 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12517 +   GNU General Public License for more details.
12518 +
12519 +   You should have received a copy of the GNU General Public License
12520 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
12521 +
12522 +struct {
12523 +  int field;
12524 +} staticstruct = { 1 };
12525 diff --git a/gdb/testsuite/gdb.base/internal-var-field-address.exp b/gdb/testsuite/gdb.base/internal-var-field-address.exp
12526 new file mode 100644
12527 index 0000000..6d82e73
12528 --- /dev/null
12529 +++ b/gdb/testsuite/gdb.base/internal-var-field-address.exp
12530 @@ -0,0 +1,26 @@
12531 +# Copyright 2009 Free Software Foundation, Inc.
12532 +
12533 +# This program is free software; you can redistribute it and/or modify
12534 +# it under the terms of the GNU General Public License as published by
12535 +# the Free Software Foundation; either version 3 of the License, or
12536 +# (at your option) any later version.
12537 +#
12538 +# This program is distributed in the hope that it will be useful,
12539 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12540 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12541 +# GNU General Public License for more details.
12542 +#
12543 +# You should have received a copy of the GNU General Public License
12544 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
12545 +
12546 +set test internal-var-field-address
12547 +set binfile ${test}.x
12548 +if  { [gdb_compile "${srcdir}/${subdir}/${test}.c" "${objdir}/${subdir}/${binfile}" object {debug}] != "" } {
12549 +    untested "Couldn't compile test program"
12550 +    return -1
12551 +}
12552 +
12553 +clean_restart $binfile
12554 +
12555 +gdb_test {set $varstruct = staticstruct}
12556 +gdb_test {p $varstruct.field} " = 1"
12557 diff --git a/gdb/testsuite/gdb.base/vla-overflow.c b/gdb/testsuite/gdb.base/vla-overflow.c
12558 new file mode 100644
12559 index 0000000..c5d5ee0
12560 --- /dev/null
12561 +++ b/gdb/testsuite/gdb.base/vla-overflow.c
12562 @@ -0,0 +1,30 @@
12563 +/* This testcase is part of GDB, the GNU debugger.
12564 +
12565 +   Copyright 2008 Free Software Foundation, Inc.
12566 +
12567 +   This program is free software; you can redistribute it and/or modify
12568 +   it under the terms of the GNU General Public License as published by
12569 +   the Free Software Foundation; either version 3 of the License, or
12570 +   (at your option) any later version.
12571 +
12572 +   This program is distributed in the hope that it will be useful,
12573 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
12574 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12575 +   GNU General Public License for more details.
12576 +
12577 +   You should have received a copy of the GNU General Public License
12578 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
12579 +
12580 +#include <stdlib.h>
12581 +
12582 +int
12583 +main (int argc, char **argv)
12584 +{
12585 +  int array[argc];
12586 +
12587 +  array[0] = array[0];
12588 +
12589 +  abort ();
12590 +
12591 +  return 0;
12592 +}
12593 diff --git a/gdb/testsuite/gdb.base/vla-overflow.exp b/gdb/testsuite/gdb.base/vla-overflow.exp
12594 new file mode 100644
12595 index 0000000..24a608f
12596 --- /dev/null
12597 +++ b/gdb/testsuite/gdb.base/vla-overflow.exp
12598 @@ -0,0 +1,109 @@
12599 +# Copyright 2008 Free Software Foundation, Inc.
12600 +
12601 +# This program is free software; you can redistribute it and/or modify
12602 +# it under the terms of the GNU General Public License as published by
12603 +# the Free Software Foundation; either version 3 of the License, or
12604 +# (at your option) any later version.
12605 +#
12606 +# This program is distributed in the hope that it will be useful,
12607 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12608 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12609 +# GNU General Public License for more details.
12610 +#
12611 +# You should have received a copy of the GNU General Public License
12612 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
12613 +
12614 +# We could crash in:
12615 +# #0  block_linkage_function (bl=0x0) at ../../gdb/block.c:69
12616 +# #1  in dwarf_block_get_frame_base (...) at ../../gdb/dwarf2block.c:97
12617 +#   97   framefunc = block_linkage_function (get_frame_block (frame, NULL));
12618 +# #2  in execute_stack_op (...) at ../../gdb/dwarf2expr.c:496
12619 +# #3  in dwarf_block_exec_core () at ../../gdb/dwarf2block.c:156
12620 +# #4  dwarf_block_exec (...) at ../../gdb/dwarf2block.c:206
12621 +# #5  in range_type_count_bound_internal (...) at ../../gdb/gdbtypes.c:1430
12622 +# #6  in create_array_type (...) at ../../gdb/gdbtypes.c:840
12623 +# ...
12624 +# #21 in psymtab_to_symtab (...) at ../../gdb/symfile.c:292
12625 +# ...
12626 +# #29 in backtrace_command_1 () at ../../gdb/stack.c:1273
12627 +
12628 +set testfile vla-overflow
12629 +set shfile ${objdir}/${subdir}/${testfile}-gdb.sh
12630 +set srcfile ${testfile}.c
12631 +set binfile ${objdir}/${subdir}/${testfile}
12632 +if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
12633 +    untested "Couldn't compile test program"
12634 +    return -1
12635 +}
12636 +
12637 +set f [open "|getconf PAGESIZE" "r"]
12638 +gets $f pagesize
12639 +close $f
12640 +
12641 +gdb_exit
12642 +gdb_start
12643 +gdb_reinitialize_dir $srcdir/$subdir
12644 +gdb_load ${binfile}
12645 +
12646 +set pid_of_gdb [exp_pid -i [board_info host fileid]]
12647 +
12648 +if { [runto_main] < 0 } {
12649 +    untested vla-overflow
12650 +    return -1
12651 +}
12652 +
12653 +# Get the GDB memory size when we stay at main.
12654 +
12655 +proc memory_v_pages_get {} {
12656 +    global pid_of_gdb pagesize
12657 +    set fd [open "/proc/$pid_of_gdb/statm"]
12658 +    gets $fd line
12659 +    close $fd
12660 +    # number of pages of virtual memory
12661 +    scan $line "%d" drs
12662 +    return $drs
12663 +}
12664 +
12665 +set pages_found [memory_v_pages_get]
12666 +
12667 +# s390x with glibc-debuginfo.s390x installed used approx. 16MB.
12668 +set mb_reserve 40
12669 +verbose -log "pages_found = $pages_found, mb_reserve = $mb_reserve"
12670 +set kb_found [expr $pages_found * $pagesize / 1024]
12671 +set kb_permit [expr $kb_found + 1 * 1024 + $mb_reserve * 1024]
12672 +verbose -log "kb_found = $kb_found, kb_permit = $kb_permit"
12673 +
12674 +# Create the ulimit wrapper.
12675 +set f [open $shfile "w"]
12676 +puts $f "#! /bin/sh"
12677 +puts $f "ulimit -v $kb_permit"
12678 +puts $f "exec $GDB \"\$@\""
12679 +close $f
12680 +remote_exec host "chmod +x $shfile"
12681 +
12682 +gdb_exit
12683 +set GDBold $GDB
12684 +set GDB "$shfile"
12685 +gdb_start
12686 +set GDB $GDBold
12687 +
12688 +gdb_reinitialize_dir $srcdir/$subdir
12689 +gdb_load ${binfile}
12690 +
12691 +set pid_of_gdb [exp_pid -i [board_info host fileid]]
12692 +
12693 +# Check the size again after the second run.
12694 +# We must not stop in main as it would cache `array' and never crash later.
12695 +
12696 +gdb_run_cmd
12697 +
12698 +verbose -log "kb_found before abort() = [expr [memory_v_pages_get] * $pagesize / 1024]"
12699 +
12700 +gdb_test "" "Program received signal SIGABRT, Aborted..*" "Enter abort()"
12701 +
12702 +verbose -log "kb_found in abort() = [expr [memory_v_pages_get] * $pagesize / 1024]"
12703 +
12704 +# `abort' can get expressed as `*__GI_abort'.
12705 +gdb_test "bt" "in \[^ \]*abort \\(.* in main \\(.*" "Backtrace after abort()"
12706 +
12707 +verbose -log "kb_found in bt after abort() = [expr [memory_v_pages_get] * $pagesize / 1024]"
12708 diff --git a/gdb/testsuite/gdb.base/vla.c b/gdb/testsuite/gdb.base/vla.c
12709 new file mode 100644
12710 index 0000000..e1f3ed1
12711 --- /dev/null
12712 +++ b/gdb/testsuite/gdb.base/vla.c
12713 @@ -0,0 +1,55 @@
12714 +/* This testcase is part of GDB, the GNU debugger.
12715 +
12716 +   Copyright 2008 Free Software Foundation, Inc.
12717 +
12718 +   This program is free software; you can redistribute it and/or modify
12719 +   it under the terms of the GNU General Public License as published by
12720 +   the Free Software Foundation; either version 3 of the License, or
12721 +   (at your option) any later version.
12722 +
12723 +   This program is distributed in the hope that it will be useful,
12724 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
12725 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12726 +   GNU General Public License for more details.
12727 +
12728 +   You should have received a copy of the GNU General Public License
12729 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
12730 +
12731 +#include <string.h>
12732 +
12733 +void
12734 +marker (void)
12735 +{
12736 +}
12737 +
12738 +void
12739 +bar (char *a, char *b, char *c, int size)
12740 +{
12741 +  memset (a, '1', size);
12742 +  memset (b, '2', size);
12743 +  memset (c, '3', 48);
12744 +}
12745 +
12746 +void
12747 +foo (int size)
12748 +{
12749 +  char temp1[size];
12750 +  char temp3[48];
12751 +
12752 +  temp1[size - 1] = '\0';
12753 +  {
12754 +    char temp2[size];
12755 +
12756 +    bar (temp1, temp2, temp3, size);
12757 +
12758 +    marker (); /* break-here */
12759 +  }
12760 +}
12761 +
12762 +int
12763 +main (void)
12764 +{
12765 +  foo (26);
12766 +  foo (78);
12767 +  return 0;
12768 +}
12769 diff --git a/gdb/testsuite/gdb.base/vla.exp b/gdb/testsuite/gdb.base/vla.exp
12770 new file mode 100644
12771 index 0000000..5da7378
12772 --- /dev/null
12773 +++ b/gdb/testsuite/gdb.base/vla.exp
12774 @@ -0,0 +1,62 @@
12775 +# Copyright 2008 Free Software Foundation, Inc.
12776 +
12777 +# This program is free software; you can redistribute it and/or modify
12778 +# it under the terms of the GNU General Public License as published by
12779 +# the Free Software Foundation; either version 3 of the License, or
12780 +# (at your option) any later version.
12781 +#
12782 +# This program is distributed in the hope that it will be useful,
12783 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12784 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12785 +# GNU General Public License for more details.
12786 +#
12787 +# You should have received a copy of the GNU General Public License
12788 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
12789 +
12790 +set testfile vla
12791 +set srcfile ${testfile}.c
12792 +set binfile ${objdir}/${subdir}/${testfile}
12793 +if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
12794 +    untested "Couldn't compile test program"
12795 +    return -1
12796 +}
12797 +
12798 +gdb_exit
12799 +gdb_start
12800 +gdb_reinitialize_dir $srcdir/$subdir
12801 +gdb_load ${binfile}
12802 +
12803 +if ![runto_main] {
12804 +    untested vla
12805 +    return -1
12806 +}
12807 +
12808 +gdb_breakpoint [gdb_get_line_number "break-here"]
12809 +
12810 +gdb_continue_to_breakpoint "break-here"
12811 +
12812 +gdb_test "whatis temp1" "type = char \\\[variable\\\]" "first: whatis temp1"
12813 +gdb_test "whatis temp2" "type = char \\\[variable\\\]" "first: whatis temp2"
12814 +gdb_test "whatis temp3" "type = char \\\[48\\\]" "first: whatis temp3"
12815 +
12816 +gdb_test "ptype temp1" "type = char \\\[26\\\]" "first: ptype temp1"
12817 +gdb_test "ptype temp2" "type = char \\\[26\\\]" "first: ptype temp2"
12818 +gdb_test "ptype temp3" "type = char \\\[48\\\]" "first: ptype temp3"
12819 +
12820 +gdb_test "p temp1" " = '1' <repeats 26 times>" "first: print temp1"
12821 +gdb_test "p temp2" " = '2' <repeats 26 times>" "first: print temp2"
12822 +gdb_test "p temp3" " = '3' <repeats 48 times>" "first: print temp3"
12823 +
12824 +gdb_continue_to_breakpoint "break-here"
12825 +
12826 +gdb_test "whatis temp1" "type = char \\\[variable\\\]" "second: whatis temp1"
12827 +gdb_test "whatis temp2" "type = char \\\[variable\\\]" "second: whatis temp2"
12828 +gdb_test "whatis temp3" "type = char \\\[48\\\]" "second: whatis temp3"
12829 +
12830 +gdb_test "ptype temp1" "type = char \\\[78\\\]" "second: ptype temp1"
12831 +gdb_test "ptype temp2" "type = char \\\[78\\\]" "second: ptype temp2"
12832 +gdb_test "ptype temp3" "type = char \\\[48\\\]" "second: ptype temp3"
12833 +
12834 +gdb_test "p temp1" " = '1' <repeats 78 times>" "second: print temp1"
12835 +gdb_test "p temp2" " = '2' <repeats 78 times>" "second: print temp2"
12836 +gdb_test "p temp3" " = '3' <repeats 48 times>" "second: print temp3"
12837 diff --git a/gdb/testsuite/gdb.cp/gdb9593.cc b/gdb/testsuite/gdb.cp/gdb9593.cc
12838 new file mode 100644
12839 index 0000000..783c962
12840 --- /dev/null
12841 +++ b/gdb/testsuite/gdb.cp/gdb9593.cc
12842 @@ -0,0 +1,180 @@
12843 +/* This testcase is part of GDB, the GNU debugger.
12844 +
12845 +   Copyright 2008, 2009 Free Software Foundation, Inc.
12846 +
12847 +   This program is free software; you can redistribute it and/or modify
12848 +   it under the terms of the GNU General Public License as published by
12849 +   the Free Software Foundation; either version 3 of the License, or
12850 +   (at your option) any later version.
12851 +
12852 +   This program is distributed in the hope that it will be useful,
12853 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
12854 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12855 +   GNU General Public License for more details.
12856 +
12857 +   You should have received a copy of the GNU General Public License
12858 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.
12859 +   */
12860 +#include <iostream>
12861 +
12862 +using namespace std;
12863 +
12864 +class NextOverThrowDerivates
12865 +{
12866 +
12867 +public:
12868 +
12869 +
12870 +  // Single throw an exception in this function.
12871 +  void function1() 
12872 +  {
12873 +    throw 20;
12874 +  }
12875 +
12876 +  // Throw an exception in another function.
12877 +  void function2() 
12878 +  {
12879 +    function1();
12880 +  }
12881 +
12882 +  // Throw an exception in another function, but handle it
12883 +  // locally.
12884 +  void function3 () 
12885 +  {
12886 +    {
12887 +      try
12888 +       {
12889 +         function1 ();
12890 +       }
12891 +      catch (...) 
12892 +       {
12893 +         cout << "Caught and handled function1 exception" << endl;
12894 +       }
12895 +    }
12896 +  }
12897 +
12898 +  void rethrow ()
12899 +  {
12900 +    try
12901 +      {
12902 +       function1 ();
12903 +      }
12904 +    catch (...)
12905 +      {
12906 +       throw;
12907 +      }
12908 +  }
12909 +
12910 +  void finish ()
12911 +  {
12912 +    // We use this to test that a "finish" here does not end up in
12913 +    // this frame, but in the one above.
12914 +    try
12915 +      {
12916 +       function1 ();
12917 +      }
12918 +    catch (int x)
12919 +      {
12920 +      }
12921 +    function1 ();              // marker for until
12922 +  }
12923 +
12924 +  void until ()
12925 +  {
12926 +    function1 ();
12927 +    function1 ();              // until here
12928 +  }
12929 +
12930 +};
12931 +NextOverThrowDerivates next_cases;
12932 +
12933 +
12934 +int main () 
12935 +{ 
12936 +  try
12937 +    {
12938 +      next_cases.function1 ();
12939 +    }
12940 +  catch (...)
12941 +    {
12942 +      // Discard
12943 +    }
12944 +
12945 +  try
12946 +    {
12947 +      next_cases.function2 ();
12948 +    }
12949 +  catch (...)
12950 +    {
12951 +      // Discard
12952 +    }
12953 +
12954 +  try
12955 +    {
12956 +      // This is duplicated so we can next over one but step into
12957 +      // another.
12958 +      next_cases.function2 ();
12959 +    }
12960 +  catch (...)
12961 +    {
12962 +      // Discard
12963 +    }
12964 +
12965 +  next_cases.function3 ();
12966 +
12967 +  try
12968 +    {
12969 +      next_cases.rethrow ();
12970 +    }
12971 +  catch (...)
12972 +    {
12973 +      // Discard
12974 +    }
12975 +
12976 +  try
12977 +    {
12978 +      // Another duplicate so we can test "finish".
12979 +      next_cases.function2 ();
12980 +    }
12981 +  catch (...)
12982 +    {
12983 +      // Discard
12984 +    }
12985 +
12986 +  // Another test for "finish".
12987 +  try
12988 +    {
12989 +      next_cases.finish ();
12990 +    }
12991 +  catch (...)
12992 +    {
12993 +    }
12994 +
12995 +  // Test of "until".
12996 +  try
12997 +    {
12998 +      next_cases.finish ();
12999 +    }
13000 +  catch (...)
13001 +    {
13002 +    }
13003 +
13004 +  // Test of "until" with an argument.
13005 +  try
13006 +    {
13007 +      next_cases.until ();
13008 +    }
13009 +  catch (...)
13010 +    {
13011 +    }
13012 +
13013 +  // Test of "advance".
13014 +  try
13015 +    {
13016 +      next_cases.until ();
13017 +    }
13018 +  catch (...)
13019 +    {
13020 +    }
13021 +}
13022 +
13023 diff --git a/gdb/testsuite/gdb.cp/gdb9593.exp b/gdb/testsuite/gdb.cp/gdb9593.exp
13024 new file mode 100644
13025 index 0000000..3dad7ca
13026 --- /dev/null
13027 +++ b/gdb/testsuite/gdb.cp/gdb9593.exp
13028 @@ -0,0 +1,182 @@
13029 +# Copyright 2008, 2009 Free Software Foundation, Inc.
13030 +
13031 +# This program is free software; you can redistribute it and/or modify
13032 +# it under the terms of the GNU General Public License as published by
13033 +# the Free Software Foundation; either version 3 of the License, or
13034 +# (at your option) any later version.
13035 +#
13036 +# This program is distributed in the hope that it will be useful,
13037 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13038 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13039 +# GNU General Public License for more details.
13040 +#
13041 +# You should have received a copy of the GNU General Public License
13042 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
13043 +
13044 +
13045 +if $tracelevel then {
13046 +    strace $tracelevel
13047 +}
13048 +
13049 +if { [skip_cplus_tests] } { continue }
13050 +
13051 +set testfile "gdb9593"
13052 +set srcfile ${testfile}.cc
13053 +set binfile $objdir/$subdir/$testfile
13054 +
13055 +# Create and source the file that provides information about the compiler
13056 +# used to compile the test case.
13057 +if [get_compiler_info ${binfile} "c++"] {
13058 +    untested gdb9593.exp
13059 +    return -1
13060 +}
13061 +
13062 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
13063 +    untested gdb9593.exp
13064 +    return -1
13065 +}
13066 +
13067 +# Some targets can't do function calls, so don't even bother with this
13068 +# test.
13069 +if [target_info exists gdb,cannot_call_functions] {
13070 +    setup_xfail "*-*-*" 9593
13071 +    fail "This target can not call functions"
13072 +    continue
13073 +}
13074 +
13075 +gdb_exit
13076 +gdb_start
13077 +gdb_reinitialize_dir $srcdir/$subdir
13078 +gdb_load ${binfile}
13079 +
13080 +if ![runto_main] then {
13081 +    perror "couldn't run to main"
13082 +    continue
13083 +} 
13084 +
13085 +# See whether we have the needed unwinder hooks.
13086 +set ok 1
13087 +gdb_test_multiple "print _Unwind_DebugHook" "check for unwinder hook" {
13088 +    -re "= .*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
13089 +       pass "check for unwinder hook"
13090 +    }
13091 +    -re "No symbol .* in current context.\r\n$gdb_prompt $" {
13092 +       # Pass the test so we don't get bogus fails in the results.
13093 +       pass "check for unwinder hook"
13094 +       set ok 0
13095 +    }
13096 +}
13097 +if {!$ok} {
13098 +    untested gdb9593.exp
13099 +    return -1
13100 +}
13101 +
13102 +# See http://sourceware.org/bugzilla/show_bug.cgi?id=9593
13103 +
13104 +gdb_test "next" \
13105 +    ".*catch (...).*" \
13106 +    "next over a throw 1"
13107 +
13108 +gdb_test "next" \
13109 +  ".*next_cases.function2.*" \
13110 +  "next past catch 1"
13111 +
13112 +gdb_test "next" \
13113 +    ".*catch (...).*" \
13114 +    "next over a throw 2"
13115 +
13116 +gdb_test "next" \
13117 +  ".*next_cases.function2.*" \
13118 +  "next past catch 2"
13119 +
13120 +gdb_test "step" \
13121 +  ".*function1().*" \
13122 +  "step into function2 1"
13123 +
13124 +gdb_test "next" \
13125 +    ".*catch (...).*" \
13126 +    "next over a throw 3"
13127 +
13128 +gdb_test "next" \
13129 +  ".*next_cases.function3.*" \
13130 +  "next past catch 3"
13131 +
13132 +gdb_test "next" \
13133 +  ".*next_cases.rethrow.*" \
13134 +    "next over a throw 4"
13135 +
13136 +gdb_test "next" \
13137 +  ".*catch (...).*" \
13138 +  "next over a rethrow"
13139 +
13140 +gdb_test "next" \
13141 +  ".*next_cases.function2.*" \
13142 +  "next after a rethrow"
13143 +
13144 +gdb_test "step" \
13145 +  ".*function1().*" \
13146 +  "step into function2 2"
13147 +
13148 +gdb_test "finish" \
13149 +  ".*catch (...).*" \
13150 +  "finish 1"
13151 +
13152 +gdb_test "next" \
13153 +  ".*next_cases.finish ().*" \
13154 +  "next past catch 4"
13155 +
13156 +gdb_test "step" \
13157 +  ".*function1 ().*" \
13158 +  "step into finish method"
13159 +
13160 +gdb_test "finish" \
13161 +  ".*catch (...).*" \
13162 +  "finish 2"
13163 +
13164 +gdb_test "next" \
13165 +  ".*next_cases.finish ().*" \
13166 +  "next past catch 5"
13167 +
13168 +gdb_test "step" \
13169 +  ".*function1 ().*" \
13170 +  "step into finish, for until"
13171 +
13172 +gdb_test "until" \
13173 +  ".*function1 ().*" \
13174 +  "until with no argument 1"
13175 +
13176 +set line [gdb_get_line_number "marker for until" $testfile.cc]
13177 +
13178 +gdb_test "until $line" \
13179 +  ".*function1 ().*" \
13180 +  "next past catch 6"
13181 +
13182 +gdb_test "until" \
13183 +  ".*catch (...).*" \
13184 +  "until with no argument 2"
13185 +
13186 +set line [gdb_get_line_number "until here" $testfile.cc]
13187 +
13188 +gdb_test "next" \
13189 +  ".*next_cases.until ().*" \
13190 +  "next past catch 6"
13191 +
13192 +gdb_test "step" \
13193 +  ".*function1 ().*" \
13194 +  "step into until"
13195 +
13196 +gdb_test "until $line" \
13197 +  ".*catch (...).*" \
13198 +  "until-over-throw"
13199 +
13200 +gdb_test "next" \
13201 +  ".*next_cases.until ().*" \
13202 +  "next past catch 7"
13203 +
13204 +gdb_test "step" \
13205 +  ".*function1 ().*" \
13206 +  "step into until, for advance"
13207 +
13208 +gdb_test "advance $line" \
13209 +  ".*catch (...).*" \
13210 +  "advance-over-throw"
13211 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.S b/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.S
13212 new file mode 100644
13213 index 0000000..7fb00ea
13214 --- /dev/null
13215 +++ b/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.S
13216 @@ -0,0 +1,212 @@
13217 +/* This testcase is part of GDB, the GNU debugger.
13218 +
13219 +   Copyright 2010 Free Software Foundation, Inc.
13220 +
13221 +   This program is free software; you can redistribute it and/or modify
13222 +   it under the terms of the GNU General Public License as published by
13223 +   the Free Software Foundation; either version 3 of the License, or
13224 +   (at your option) any later version.
13225 +
13226 +   This program is distributed in the hope that it will be useful,
13227 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
13228 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13229 +   GNU General Public License for more details.
13230 +
13231 +   You should have received a copy of the GNU General Public License
13232 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
13233 +
13234 +/* Debug information */
13235 +
13236 +/* We will `break *main' at the very first instruction.  */
13237 +#define main_length 1
13238 +
13239 +       .section        .data
13240 +vardata:
13241 +       /* See DW_OP_lit3 + 1 (0-based).  */
13242 +       .string         "seennotseen"
13243 +
13244 +       .section        .debug_info
13245 +.Lcu1_begin:
13246 +       .4byte          .Lcu1_end - .Lcu1_start /* Length of Compilation Unit */
13247 +.Lcu1_start:
13248 +       .2byte          2                       /* DWARF version number */
13249 +       .4byte          .Ldebug_abbrev0         /* Offset Into Abbrev. Section */
13250 +       .byte           4                       /* Pointer Size (in bytes) */
13251 +
13252 +       /* CU die */
13253 +       .uleb128        1                       /* Abbrev: DW_TAG_compile_unit */
13254 +       .4byte          .Lproducer              /* DW_AT_producer */
13255 +       /* Use C++ to exploit a bug in parsing DW_AT_name "".  */
13256 +       .byte           4                       /* DW_AT_language (C++) -  */
13257 +       .4byte          main                    /* DW_AT_low_pc */
13258 +       .byte           main_length             /* DW_AT_high_pc */
13259 +
13260 +.Larray_type:
13261 +       .uleb128        2                       /* Abbrev: DW_TAG_array_type */
13262 +       .4byte          .Lchar_type-.Lcu1_begin /* DW_AT_type */
13263 +
13264 +       .uleb128        3                       /* Abbrev: DW_TAG_subrange_type */
13265 +       .4byte          .Luint_type-.Lcu1_begin /* DW_AT_type */
13266 +       .byte           0                       /* DW_AT_lower_bound */
13267 +       .4byte          .Llen_var-.Lcu1_begin   /* DW_AT_upper_bound */
13268 +       .byte           0                       /* End of children of die */
13269 +
13270 +       /* DW_AT_upper_bound is referencing an optimized-out variable.  */
13271 +.Larrayb_type:
13272 +       .uleb128        2                       /* Abbrev: DW_TAG_array_type */
13273 +       .4byte          .Lchar_type-.Lcu1_begin /* DW_AT_type */
13274 +
13275 +       .uleb128        3                       /* Abbrev: DW_TAG_subrange_type */
13276 +       .4byte          .Luint_type-.Lcu1_begin /* DW_AT_type */
13277 +       .byte           0                       /* DW_AT_lower_bound */
13278 +       .4byte          .Llenb_var-.Lcu1_begin  /* DW_AT_upper_bound */
13279 +       .byte           0                       /* End of children of die */
13280 +
13281 +.Luint_type:
13282 +       .uleb128        4                       /* Abbrev: DW_TAG_base_type */
13283 +       .4byte          .Luint_str              /* DW_AT_name */
13284 +       .byte           4                       /* DW_AT_byte_size */
13285 +       .byte           7                       /* DW_AT_encoding */
13286 +
13287 +.Lchar_type:
13288 +       .uleb128        4                       /* Abbrev: DW_TAG_base_type */
13289 +       .4byte          .Lchar_str              /* DW_AT_name */
13290 +       .byte           1                       /* DW_AT_byte_size */
13291 +       .byte           6                       /* DW_AT_encoding */
13292 +
13293 +.Llen_var:
13294 +       .uleb128        5                       /* Abbrev: DW_TAG_variable artificial */
13295 +       .byte           1                       /* DW_AT_artificial */
13296 +       .4byte          .Luint_type-.Lcu1_begin /* DW_AT_type */
13297 +       .4byte          .Llen_loclist-.Lloclist /* DW_AT_location */
13298 +
13299 +       /* optimized-out variable for b_string.  */
13300 +.Llenb_var:
13301 +       .uleb128        7                       /* Abbrev: DW_TAG_variable artificial no DW_AT_location */
13302 +       .byte           1                       /* DW_AT_artificial */
13303 +       .4byte          .Luint_type-.Lcu1_begin /* DW_AT_type */
13304 +
13305 +       .uleb128        6                       /* Abbrev: DW_TAG_variable DW_FORM_string */
13306 +       .string         "a_string"              /* DW_AT_name */
13307 +       .4byte          .Larray_type-.Lcu1_begin /* DW_AT_type */
13308 +       .byte           2f - 1f                 /* DW_AT_location */
13309 +1:     .byte           3                       /*   DW_OP_addr */
13310 +       .4byte          vardata                 /*   <addr> */
13311 +2:
13312 +
13313 +       /* DW_AT_upper_bound is referencing an optimized-out variable.  */
13314 +       .uleb128        6                       /* Abbrev: DW_TAG_variable DW_FORM_string */
13315 +       .string         "b_string"              /* DW_AT_name */
13316 +       .4byte          .Larrayb_type-.Lcu1_begin /* DW_AT_type */
13317 +       .byte           2f - 1f                 /* DW_AT_location */
13318 +1:     .byte           3                       /*   DW_OP_addr */
13319 +       .4byte          vardata                 /*   <addr> */
13320 +2:
13321 +
13322 +       .byte           0                       /* End of children of CU */
13323 +.Lcu1_end:
13324 +
13325 +       .section        .debug_loc
13326 +.Lloclist:
13327 +.Llen_loclist:
13328 +       .4byte  0                       # Location list begin address
13329 +       .4byte  main_length             # Location list end address
13330 +       .value  2f-1f   # Location expression size
13331 +1:     .byte   0x33    # DW_OP_lit3
13332 +       .byte   0x9f    # DW_OP_stack_value
13333 +2:
13334 +       .quad   0x0     # Location list terminator begin (*.LLST2)
13335 +       .quad   0x0     # Location list terminator end (*.LLST2)
13336 +
13337 +       .section .debug_abbrev
13338 +.Ldebug_abbrev0:
13339 +       .uleb128        1                       /* Abbrev code */
13340 +       .uleb128        0x11                    /* DW_TAG_compile_unit */
13341 +       .byte           0x1                     /* has_children */
13342 +       .uleb128        0x25                    /* DW_AT_producer */
13343 +       .uleb128        0xe                     /* DW_FORM_strp */
13344 +       .uleb128        0x13                    /* DW_AT_language */
13345 +       .uleb128        0xb                     /* DW_FORM_data1 */
13346 +       .uleb128        0x11                    /* DW_AT_low_pc */
13347 +       .uleb128        0x1                     /* DW_FORM_addr */
13348 +       .uleb128        0x12                    /* DW_AT_high_pc */
13349 +       .uleb128        0xb                     /* DW_FORM_data1 */
13350 +       .byte           0x0                     /* Terminator */
13351 +       .byte           0x0                     /* Terminator */
13352 +
13353 +       .uleb128        2                       /* Abbrev code */
13354 +       .uleb128        0x1                     /* TAG: DW_TAG_array_type */
13355 +       .byte           0x1                     /* DW_children_yes */
13356 +       .uleb128        0x49                    /* DW_AT_type */
13357 +       .uleb128        0x13                    /* DW_FORM_ref4 */
13358 +       .byte           0x0                     /* Terminator */
13359 +       .byte           0x0                     /* Terminator */
13360 +
13361 +       .uleb128        3                       /* Abbrev code */
13362 +       .uleb128        0x21                    /* DW_TAG_subrange_type */
13363 +       .byte           0x0                     /* no children */
13364 +       .uleb128        0x49                    /* DW_AT_type */
13365 +       .uleb128        0x13                    /* DW_FORM_ref4 */
13366 +       .uleb128        0x22                    /* DW_AT_lower_bound */
13367 +       .uleb128        0xb                     /* DW_FORM_data1 */
13368 +       .uleb128        0x2f                    /* DW_AT_upper_bound */
13369 +       .uleb128        0x13                    /* DW_FORM_ref4 */
13370 +       .byte           0x0                     /* Terminator */
13371 +       .byte           0x0                     /* Terminator */
13372 +
13373 +       .uleb128        4                       /* Abbrev code */
13374 +       .uleb128        0x24                    /* DW_TAG_base_type */
13375 +       .byte           0x0                     /* no_children */
13376 +       .uleb128        0x3                     /* DW_AT_name */
13377 +       .uleb128        0xe                     /* DW_FORM_strp */
13378 +       .uleb128        0xb                     /* DW_AT_byte_size */
13379 +       .uleb128        0xb                     /* DW_FORM_data1 */
13380 +       .uleb128        0x3e                    /* DW_AT_encoding */
13381 +       .uleb128        0xb                     /* DW_FORM_data1 */
13382 +       .byte           0x0                     /* Terminator */
13383 +       .byte           0x0                     /* Terminator */
13384 +
13385 +       .uleb128        5                       /* Abbrev code */
13386 +       .uleb128        0x34                    /* DW_TAG_variable */
13387 +       .byte           0x0                     /* no_children */
13388 +       .uleb128        0x34                    /* DW_AT_artificial */
13389 +       .uleb128        0x0c                    /* DW_FORM_flag */
13390 +       .uleb128        0x49                    /* DW_AT_type */
13391 +       .uleb128        0x13                    /* DW_FORM_ref4 */
13392 +       .uleb128        0x02                    /* DW_AT_location */
13393 +       .uleb128        0x06                    /* DW_FORM_data4 */
13394 +       .byte           0x0                     /* Terminator */
13395 +       .byte           0x0                     /* Terminator */
13396 +
13397 +       .uleb128        6                       /* Abbrev code */
13398 +       .uleb128        0x34                    /* DW_TAG_variable */
13399 +       .byte           0x0                     /* no_children */
13400 +       .uleb128        0x3                     /* DW_AT_name */
13401 +       .uleb128        0x8                     /* DW_FORM_string */
13402 +       .uleb128        0x49                    /* DW_AT_type */
13403 +       .uleb128        0x13                    /* DW_FORM_ref4 */
13404 +       .uleb128        0x2                     /* DW_AT_location */
13405 +       .uleb128        0xa                     /* DW_FORM_block1 */
13406 +       .byte           0x0                     /* Terminator */
13407 +       .byte           0x0                     /* Terminator */
13408 +
13409 +       .uleb128        7                       /* Abbrev code */
13410 +       .uleb128        0x34                    /* DW_TAG_variable */
13411 +       .byte           0x0                     /* no_children */
13412 +       .uleb128        0x34                    /* DW_AT_artificial */
13413 +       .uleb128        0x0c                    /* DW_FORM_flag */
13414 +       .uleb128        0x49                    /* DW_AT_type */
13415 +       .uleb128        0x13                    /* DW_FORM_ref4 */
13416 +       .byte           0x0                     /* Terminator */
13417 +       .byte           0x0                     /* Terminator */
13418 +
13419 +       .byte           0x0                     /* Terminator */
13420 +
13421 +/* String table */
13422 +       .section .debug_str
13423 +.Lproducer:
13424 +       .string         "GNU C 3.3.3"
13425 +.Lchar_str:
13426 +       .string         "char"
13427 +.Luint_str:
13428 +       .string         "unsigned int"
13429 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.exp b/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.exp
13430 new file mode 100644
13431 index 0000000..5dbed3f
13432 --- /dev/null
13433 +++ b/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.exp
13434 @@ -0,0 +1,51 @@
13435 +# Copyright 2010 Free Software Foundation, Inc.
13436 +
13437 +# This program is free software; you can redistribute it and/or modify
13438 +# it under the terms of the GNU General Public License as published by
13439 +# the Free Software Foundation; either version 3 of the License, or
13440 +# (at your option) any later version.
13441 +#
13442 +# This program is distributed in the hope that it will be useful,
13443 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13444 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13445 +# GNU General Public License for more details.
13446 +#
13447 +# You should have received a copy of the GNU General Public License
13448 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
13449 +
13450 +# Test printing variable with dynamic bounds which reference a different
13451 +# (artificial in the GCC case) variable containing loclist as its location.
13452 +# This testcase uses value (not address) of the referenced variable:
13453 +# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43762
13454 +
13455 +# This test can only be run on targets which support DWARF-2 and use gas.
13456 +# For now pick a sampling of likely targets.
13457 +if {![istarget *-*-linux*]
13458 +    && ![istarget *-*-gnu*]
13459 +    && ![istarget *-*-elf*]
13460 +    && ![istarget *-*-openbsd*]
13461 +    && ![istarget arm-*-eabi*]
13462 +    && ![istarget powerpc-*-eabi*]} {
13463 +    return 0
13464 +}
13465 +
13466 +set testfile dw2-bound-loclist
13467 +if { [prepare_for_testing ${testfile}.exp ${testfile} [list ${testfile}.S main.c] {}] } {
13468 +    return -1
13469 +}
13470 +
13471 +# Verify it behaves at least as an unbound array without inferior.
13472 +
13473 +gdb_test "p a_string" { = 0x[0-9a-f]+ "seennotseen"}
13474 +gdb_test "ptype a_string" {type = char \[\]}
13475 +
13476 +# Not runto_main as dw2-bound-loclist.S handles only the first byte of main.
13477 +if ![runto "*main"] {
13478 +    return -1
13479 +}
13480 +
13481 +gdb_test "p a_string" { = "seen"}
13482 +gdb_test "ptype a_string" {type = char \[4\]}
13483 +
13484 +gdb_test "p b_string" { = (0x[0-9a-f]+ )?"seennotseen"}
13485 +gdb_test "ptype b_string" {type = char \[\]}
13486 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-stripped.c b/gdb/testsuite/gdb.dwarf2/dw2-stripped.c
13487 new file mode 100644
13488 index 0000000..1f02d90
13489 --- /dev/null
13490 +++ b/gdb/testsuite/gdb.dwarf2/dw2-stripped.c
13491 @@ -0,0 +1,42 @@
13492 +/* This testcase is part of GDB, the GNU debugger.
13493 +
13494 +   Copyright 2004 Free Software Foundation, Inc.
13495 +
13496 +   This program is free software; you can redistribute it and/or modify
13497 +   it under the terms of the GNU General Public License as published by
13498 +   the Free Software Foundation; either version 2 of the License, or
13499 +   (at your option) any later version.
13500 +
13501 +   This program is distributed in the hope that it will be useful,
13502 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
13503 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13504 +   GNU General Public License for more details.
13505
13506 +   You should have received a copy of the GNU General Public License
13507 +   along with this program; if not, write to the Free Software
13508 +   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
13509 +   USA.  */
13510 +
13511 +
13512 +/* The function `func1' traced into must have debug info on offset > 0;
13513 +   (DW_UNSND (attr)).  This is the reason of `func0' existence.  */
13514 +
13515 +void
13516 +func0(int a, int b)
13517 +{
13518 +}
13519 +
13520 +/* `func1' being traced into must have some arguments to dump.  */
13521 +
13522 +void
13523 +func1(int a, int b)
13524 +{
13525 +  func0 (a,b);
13526 +}
13527 +
13528 +int
13529 +main(void)
13530 +{
13531 +  func1 (1, 2);
13532 +  return 0;
13533 +}
13534 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp b/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp
13535 new file mode 100644
13536 index 0000000..1c6e84a
13537 --- /dev/null
13538 +++ b/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp
13539 @@ -0,0 +1,79 @@
13540 +# Copyright 2006 Free Software Foundation, Inc.
13541 +
13542 +# This program is free software; you can redistribute it and/or modify
13543 +# it under the terms of the GNU General Public License as published by
13544 +# the Free Software Foundation; either version 2 of the License, or
13545 +# (at your option) any later version.
13546 +# 
13547 +# This program is distributed in the hope that it will be useful,
13548 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13549 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13550 +# GNU General Public License for more details.
13551 +# 
13552 +# You should have received a copy of the GNU General Public License
13553 +# along with this program; if not, write to the Free Software
13554 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
13555 +
13556 +# Minimal DWARF-2 unit test
13557 +
13558 +# This test can only be run on targets which support DWARF-2.
13559 +# For now pick a sampling of likely targets.
13560 +if {![istarget *-*-linux*]
13561 +    && ![istarget *-*-gnu*]
13562 +    && ![istarget *-*-elf*]
13563 +    && ![istarget *-*-openbsd*]
13564 +    && ![istarget arm-*-eabi*]
13565 +    && ![istarget powerpc-*-eabi*]} {
13566 +    return 0  
13567 +}
13568 +
13569 +set testfile "dw2-stripped"
13570 +set srcfile ${testfile}.c
13571 +set binfile ${objdir}/${subdir}/${testfile}.x
13572 +
13573 +remote_exec build "rm -f ${binfile}"
13574 +
13575 +# get the value of gcc_compiled
13576 +if [get_compiler_info ${binfile}] {
13577 +    return -1
13578 +}
13579 +
13580 +# This test can only be run on gcc as we use additional_flags=FIXME
13581 +if {$gcc_compiled == 0} {
13582 +    return 0
13583 +}
13584 +
13585 +if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-ggdb3}] != "" } {
13586 +    return -1
13587 +}
13588 +
13589 +remote_exec build "objcopy -R .debug_loc ${binfile}"
13590 +set strip_output [remote_exec build "objdump -h ${binfile}"]
13591 +
13592 +set test "stripping test file preservation"
13593 +if [ regexp ".debug_info " $strip_output]  {
13594 +    pass "$test (.debug_info preserved)"
13595 +} else {
13596 +    fail "$test (.debug_info got also stripped)"
13597 +}
13598 +
13599 +set test "stripping test file functionality"
13600 +if [ regexp ".debug_loc " $strip_output]  {
13601 +    fail "$test (.debug_loc still present)"
13602 +} else {
13603 +    pass "$test (.debug_loc stripped)"
13604 +}
13605 +
13606 +gdb_exit
13607 +gdb_start
13608 +gdb_reinitialize_dir $srcdir/$subdir
13609 +gdb_load ${binfile}
13610 +
13611 +# For C programs, "start" should stop in main().
13612 +
13613 +gdb_test "start" \
13614 +         ".*main \\(\\) at .*" \
13615 +         "start"
13616 +gdb_test "step" \
13617 +         "func.* \\(.*\\) at .*" \
13618 +         "step"
13619 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S
13620 new file mode 100644
13621 index 0000000..5fcdd84
13622 --- /dev/null
13623 +++ b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S
13624 @@ -0,0 +1,83 @@
13625 +/* This testcase is part of GDB, the GNU debugger.
13626 +
13627 +   Copyright 2009 Free Software Foundation, Inc.
13628 +
13629 +   This program is free software; you can redistribute it and/or modify
13630 +   it under the terms of the GNU General Public License as published by
13631 +   the Free Software Foundation; either version 3 of the License, or
13632 +   (at your option) any later version.
13633 +
13634 +   This program is distributed in the hope that it will be useful,
13635 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
13636 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13637 +   GNU General Public License for more details.
13638 +
13639 +   You should have received a copy of the GNU General Public License
13640 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
13641 +
13642 +/* Debug information */
13643 +
13644 +       .section .debug_info
13645 +.Lcu1_begin:
13646 +       /* CU header */
13647 +       .4byte  .Lcu1_end - .Lcu1_start         /* Length of Compilation Unit */
13648 +.Lcu1_start:
13649 +       .2byte  2                               /* DWARF Version */
13650 +       .4byte  .Labbrev1_begin                 /* Offset into abbrev section */
13651 +       .byte   4                               /* Pointer size */
13652 +
13653 +       /* CU die */
13654 +       .uleb128 1                              /* Abbrev: DW_TAG_compile_unit */
13655 +       .ascii  "dw2-struct-member-data-location.c\0"   /* DW_AT_name */
13656 +       .ascii  "GNU C 4.3.2\0"                 /* DW_AT_producer */
13657 +       .byte   1                               /* DW_AT_language (C) */
13658 +
13659 +.Ltype_uchar:
13660 +       .uleb128        2                       /* Abbrev: DW_TAG_structure_type */
13661 +       .ascii          "some_struct\0"         /* DW_AT_name */
13662 +
13663 +       .uleb128        3                       /* Abbrev: DW_TAG_member */
13664 +       .ascii          "field\0"               /* DW_AT_name */
13665 +       .byte           0                       /* DW_AT_data_member_location */
13666 +
13667 +       .byte           0                       /* End of children of some_struct */
13668 +
13669 +       .byte           0                       /* End of children of CU */
13670 +
13671 +.Lcu1_end:
13672 +
13673 +/* Abbrev table */
13674 +       .section .debug_abbrev
13675 +.Labbrev1_begin:
13676 +       .uleb128        1                       /* Abbrev code */
13677 +       .uleb128        0x11                    /* DW_TAG_compile_unit */
13678 +       .byte           1                       /* has_children */
13679 +       .uleb128        0x3                     /* DW_AT_name */
13680 +       .uleb128        0x8                     /* DW_FORM_string */
13681 +       .uleb128        0x25                    /* DW_AT_producer */
13682 +       .uleb128        0x8                     /* DW_FORM_string */
13683 +       .uleb128        0x13                    /* DW_AT_language */
13684 +       .uleb128        0xb                     /* DW_FORM_data1 */
13685 +       .byte           0x0                     /* Terminator */
13686 +       .byte           0x0                     /* Terminator */
13687 +
13688 +       .uleb128        2                       /* Abbrev code */
13689 +       .uleb128        0x13                    /* DW_TAG_structure_type */
13690 +       .byte           1                       /* has_children */
13691 +       .uleb128        0x3                     /* DW_AT_name */
13692 +       .uleb128        0x8                     /* DW_FORM_string */
13693 +       .byte           0x0                     /* Terminator */
13694 +       .byte           0x0                     /* Terminator */
13695 +
13696 +       .uleb128        3                       /* Abbrev code */
13697 +       .uleb128        0x0d                    /* DW_TAG_member */
13698 +       .byte           0                       /* has_children */
13699 +       .uleb128        0x3                     /* DW_AT_name */
13700 +       .uleb128        0x8                     /* DW_FORM_string */
13701 +       .uleb128        0x38                    /* DW_AT_data_member_location */
13702 +       .uleb128        0x0b                    /* DW_FORM_data1 */
13703 +       .byte           0x0                     /* Terminator */
13704 +       .byte           0x0                     /* Terminator */
13705 +
13706 +       .byte           0x0                     /* Terminator */
13707 +       .byte           0x0                     /* Terminator */
13708 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp
13709 new file mode 100644
13710 index 0000000..c41151c
13711 --- /dev/null
13712 +++ b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp
13713 @@ -0,0 +1,37 @@
13714 +# Copyright 2009 Free Software Foundation, Inc.
13715 +
13716 +# This program is free software; you can redistribute it and/or modify
13717 +# it under the terms of the GNU General Public License as published by
13718 +# the Free Software Foundation; either version 3 of the License, or
13719 +# (at your option) any later version.
13720 +#
13721 +# This program is distributed in the hope that it will be useful,
13722 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13723 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13724 +# GNU General Public License for more details.
13725 +#
13726 +# You should have received a copy of the GNU General Public License
13727 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
13728 +
13729 +# This test can only be run on targets which support DWARF-2 and use gas.
13730 +# For now pick a sampling of likely targets.
13731 +if {![istarget *-*-linux*]
13732 +    && ![istarget *-*-gnu*]
13733 +    && ![istarget *-*-elf*]
13734 +    && ![istarget *-*-openbsd*]
13735 +    && ![istarget arm-*-eabi*]
13736 +    && ![istarget powerpc-*-eabi*]} {
13737 +    return 0  
13738 +}
13739 +
13740 +set testfile "dw2-struct-member-data-location"
13741 +set srcfile ${testfile}.S
13742 +set binfile ${testfile}.x
13743 +
13744 +if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objdir}/${subdir}/${binfile}" object {nodebug}] != "" } {
13745 +    return -1
13746 +}
13747 +
13748 +clean_restart $binfile
13749 +
13750 +gdb_test "ptype struct some_struct" "type = struct some_struct {\[\r\n \t\]*void field;\[\r\n \t\]*}"
13751 diff --git a/gdb/testsuite/gdb.fortran/dwarf-stride.exp b/gdb/testsuite/gdb.fortran/dwarf-stride.exp
13752 new file mode 100644
13753 index 0000000..cd3486b
13754 --- /dev/null
13755 +++ b/gdb/testsuite/gdb.fortran/dwarf-stride.exp
13756 @@ -0,0 +1,42 @@
13757 +# Copyright 2009 Free Software Foundation, Inc.
13758 +
13759 +# This program is free software; you can redistribute it and/or modify
13760 +# it under the terms of the GNU General Public License as published by
13761 +# the Free Software Foundation; either version 2 of the License, or
13762 +# (at your option) any later version.
13763 +# 
13764 +# This program is distributed in the hope that it will be useful,
13765 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13766 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13767 +# GNU General Public License for more details.
13768 +# 
13769 +# You should have received a copy of the GNU General Public License
13770 +# along with this program; if not, write to the Free Software
13771 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
13772 +
13773 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
13774 +
13775 +# This file is part of the gdb testsuite.  Array element stride must not be
13776 +# specified in the number of elements but in a number of bytes instead.
13777 +# Original problem:
13778 +# (gdb) p c40pt(1)
13779 +# $1 = '0-hello', ' ' <repeats 33 times>
13780 +# (gdb) p c40pt(2)
13781 +# warning: Fortran array stride not divisible by the element size
13782 +
13783 +set testfile dwarf-stride
13784 +set srcfile ${testfile}.f90
13785 +
13786 +if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} {debug f77}] } {
13787 +    return -1
13788 +}
13789 +
13790 +if ![runto MAIN__] then {
13791 +    perror "couldn't run to breakpoint MAIN__"
13792 +    continue
13793 +}
13794 +
13795 +gdb_breakpoint [gdb_get_line_number "break-here"]
13796 +gdb_continue_to_breakpoint "break-here" ".*break-here.*"
13797 +gdb_test "p c40pt(1)" " = '0-hello.*"
13798 +gdb_test "p c40pt(2)" " = '1-hello.*"
13799 diff --git a/gdb/testsuite/gdb.fortran/dwarf-stride.f90 b/gdb/testsuite/gdb.fortran/dwarf-stride.f90
13800 new file mode 100644
13801 index 0000000..e492b3a
13802 --- /dev/null
13803 +++ b/gdb/testsuite/gdb.fortran/dwarf-stride.f90
13804 @@ -0,0 +1,40 @@
13805 +! Copyright 2009 Free Software Foundation, Inc.
13806 +!
13807 +! This program is free software; you can redistribute it and/or modify
13808 +! it under the terms of the GNU General Public License as published by
13809 +! the Free Software Foundation; either version 2 of the License, or
13810 +! (at your option) any later version.
13811 +!
13812 +! This program is distributed in the hope that it will be useful,
13813 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
13814 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13815 +! GNU General Public License for more details.
13816 +!
13817 +! You should have received a copy of the GNU General Public License
13818 +! along with this program; if not, write to the Free Software
13819 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
13820 +!
13821 +! File written by Alan Matsuoka.
13822 +
13823 +program repro
13824 +
13825 +  type small_stride
13826 +     character*40 long_string
13827 +     integer      small_pad
13828 +  end type small_stride
13829 +
13830 +  type(small_stride), dimension (20), target :: unpleasant
13831 +  character*40, pointer, dimension(:):: c40pt
13832 +
13833 +  integer i
13834 +
13835 +  do i = 0,19
13836 +     unpleasant(i+1)%small_pad = i+1
13837 +     unpleasant(i+1)%long_string = char (ichar('0') + i) // '-hello'
13838 +  end do
13839 +
13840 +  c40pt => unpleasant%long_string
13841 +
13842 +  print *, c40pt  ! break-here
13843 +
13844 +end program repro
13845 diff --git a/gdb/testsuite/gdb.fortran/dynamic.exp b/gdb/testsuite/gdb.fortran/dynamic.exp
13846 new file mode 100644
13847 index 0000000..0ccebe0
13848 --- /dev/null
13849 +++ b/gdb/testsuite/gdb.fortran/dynamic.exp
13850 @@ -0,0 +1,145 @@
13851 +# Copyright 2007 Free Software Foundation, Inc.
13852 +
13853 +# This program is free software; you can redistribute it and/or modify
13854 +# it under the terms of the GNU General Public License as published by
13855 +# the Free Software Foundation; either version 2 of the License, or
13856 +# (at your option) any later version.
13857 +# 
13858 +# This program is distributed in the hope that it will be useful,
13859 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13860 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13861 +# GNU General Public License for more details.
13862 +# 
13863 +# You should have received a copy of the GNU General Public License
13864 +# along with this program; if not, write to the Free Software
13865 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
13866 +
13867 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
13868 +
13869 +# This file is part of the gdb testsuite.  It contains tests for dynamically
13870 +# allocated Fortran arrays.
13871 +# It depends on the GCC dynamic Fortran arrays DWARF support:
13872 +#      http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22244
13873 +
13874 +set testfile "dynamic"
13875 +set srcfile ${testfile}.f90
13876 +set binfile ${objdir}/${subdir}/${testfile}
13877 +
13878 +if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f77 quiet}] != "" } {
13879 +    untested "Couldn't compile ${srcfile}"
13880 +    return -1
13881 +}
13882 +
13883 +gdb_exit
13884 +gdb_start
13885 +gdb_reinitialize_dir $srcdir/$subdir
13886 +gdb_load ${binfile}
13887 +
13888 +if ![runto MAIN__] then {
13889 +    perror "couldn't run to breakpoint MAIN__"
13890 +    continue
13891 +}
13892 +
13893 +gdb_breakpoint [gdb_get_line_number "varx-init"]
13894 +gdb_continue_to_breakpoint "varx-init"
13895 +gdb_test "p varx" "\\$\[0-9\]* = <(object|the array) is not allocated>" "p varx unallocated"
13896 +gdb_test "ptype varx" "type = <(object|the array) is not allocated>" "ptype varx unallocated"
13897 +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"
13898 +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"
13899 +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"
13900 +
13901 +gdb_breakpoint [gdb_get_line_number "varx-allocated"]
13902 +gdb_continue_to_breakpoint "varx-allocated"
13903 +# $1 = (( ( 0, 0, 0, 0, 0, 0) ( 0, 0, 0, 0, 0, 0) --- , 0) ) ( ( 0, 0, ...) ...) ...)
13904 +gdb_test "ptype varx" "type = real(\\(kind=4\\)|\\*4) \\(6,5:15,17:28\\)" "ptype varx allocated"
13905 +# Intel Fortran Compiler 10.1.008 uses -1 there, GCC uses 1.
13906 +gdb_test "p l" "\\$\[0-9\]* = (\\.TRUE\\.|4294967295)" "p l if varx allocated"
13907 +
13908 +gdb_breakpoint [gdb_get_line_number "varx-filled"]
13909 +gdb_continue_to_breakpoint "varx-filled"
13910 +gdb_test "p varx(2, 5, 17)" "\\$\[0-9\]* = 6"
13911 +gdb_test "p varx(1, 5, 17)" "\\$\[0-9\]* = 7"
13912 +gdb_test "p varx(2, 6, 18)" "\\$\[0-9\]* = 8"
13913 +gdb_test "p varx(6, 15, 28)" "\\$\[0-9\]* = 9"
13914 +# The latter one is for the Intel Fortran Compiler 10.1.008 pointer type.
13915 +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"
13916 +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"
13917 +
13918 +gdb_breakpoint [gdb_get_line_number "varv-associated"]
13919 +gdb_continue_to_breakpoint "varv-associated"
13920 +gdb_test "p varx(3, 7, 19)" "\\$\[0-9\]* = 6" "p varx(3, 7, 19) with varv associated"
13921 +gdb_test "p varv(3, 7, 19)" "\\$\[0-9\]* = 6" "p varv(3, 7, 19) associated"
13922 +# Intel Fortran Compiler 10.1.008 uses -1 there, GCC uses 1.
13923 +gdb_test "p l" "\\$\[0-9\]* = (\\.TRUE\\.|4294967295)" "p l if varv associated"
13924 +gdb_test "ptype varx" "type = real(\\(kind=4\\)|\\*4) \\(6,5:15,17:28\\)" "ptype varx with varv associated"
13925 +# Intel Fortran Compiler 10.1.008 uses the pointer type.
13926 +gdb_test "ptype varv" "type = (PTR TO -> \\( )?real(\\(kind=4\\)|\\*4) \\(6,5:15,17:28\\)\\)?" "ptype varv associated"
13927 +
13928 +gdb_breakpoint [gdb_get_line_number "varv-filled"]
13929 +gdb_continue_to_breakpoint "varv-filled"
13930 +gdb_test "p varx(3, 7, 19)" "\\$\[0-9\]* = 10" "p varx(3, 7, 19) with varv filled"
13931 +gdb_test "p varv(3, 7, 19)" "\\$\[0-9\]* = 10" "p varv(3, 7, 19) filled"
13932 +
13933 +gdb_breakpoint [gdb_get_line_number "varv-deassociated"]
13934 +gdb_continue_to_breakpoint "varv-deassociated"
13935 +# The latter one is for the Intel Fortran Compiler 10.1.008 pointer type.
13936 +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"
13937 +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"
13938 +gdb_test "p l" "\\$\[0-9\]* = \\.FALSE\\." "p l if varv deassociated"
13939 +gdb_test "p varv(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not associated\\."
13940 +gdb_test "ptype varv(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not associated\\."
13941 +
13942 +gdb_breakpoint [gdb_get_line_number "varx-deallocated"]
13943 +gdb_continue_to_breakpoint "varx-deallocated"
13944 +gdb_test "p varx" "\\$\[0-9\]* = <(object|the array) is not allocated>" "p varx deallocated"
13945 +gdb_test "ptype varx" "type = <(object|the array) is not allocated>" "ptype varx deallocated"
13946 +gdb_test "p l" "\\$\[0-9\]* = \\.FALSE\\." "p l if varx deallocated"
13947 +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"
13948 +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"
13949 +
13950 +gdb_breakpoint [gdb_get_line_number "vary-passed"]
13951 +gdb_continue_to_breakpoint "vary-passed"
13952 +# $1 = (( ( 1, 1, 1, 1, 1, 1) ( 1, 1, 1, 1, 1, 1) --- , 1) ) ( ( 1, 1, ...) ...) ...)
13953 +gdb_test "p vary" "\\$\[0-9\]* = \\(\[()1, .\]*\\)"
13954 +
13955 +gdb_breakpoint [gdb_get_line_number "vary-filled"]
13956 +gdb_continue_to_breakpoint "vary-filled"
13957 +gdb_test "ptype vary" "type = real(\\(kind=4\\)|\\*4) \\(10,10\\)"
13958 +gdb_test "p vary(1, 1)" "\\$\[0-9\]* = 8"
13959 +gdb_test "p vary(2, 2)" "\\$\[0-9\]* = 9"
13960 +gdb_test "p vary(1, 3)" "\\$\[0-9\]* = 10"
13961 +# $1 = (( ( 3, 3, 3, 3, 3, 3) ( 3, 3, 3, 3, 3, 3) --- , 3) ) ( ( 3, 3, ...) ...) ...)
13962 +gdb_test "p varw" "\\$\[0-9\]* = \\(\[()3, .\]*\\)"
13963 +
13964 +gdb_breakpoint [gdb_get_line_number "varw-almostfilled"]
13965 +gdb_continue_to_breakpoint "varw-almostfilled"
13966 +gdb_test "ptype varw" "type = real(\\(kind=4\\)|\\*4) \\(5,4,3\\)"
13967 +gdb_test "p varw(3,1,1)=1" "\\$\[0-9\]* = 1"
13968 +# $1 = (( ( 6, 5, 1, 5, 5, 5) ( 5, 5, 5, 5, 5, 5) --- , 5) ) ( ( 5, 5, ...) ...) ...)
13969 +gdb_test "p varw" "\\$\[0-9\]* = \\( *\\( *\\( *6, *5, *1,\[()5, .\]*\\)" "p varw filled"
13970 +# "up" works with GCC but other Fortran compilers may copy the values into the
13971 +# outer function only on the exit of the inner function.
13972 +# We need both variants as depending on the arch we optionally may still be
13973 +# executing the caller line or not after `finish'.
13974 +gdb_test "finish" ".*(call bar \\(y, x\\)|call foo \\(x, z\\(2:6, 4:7, 6:8\\)\\))"
13975 +gdb_test "p z(2,4,5)" "\\$\[0-9\]* = 3"
13976 +gdb_test "p z(2,4,6)" "\\$\[0-9\]* = 6"
13977 +gdb_test "p z(2,4,7)" "\\$\[0-9\]* = 5"
13978 +gdb_test "p z(4,4,6)" "\\$\[0-9\]* = 1"
13979 +
13980 +gdb_breakpoint [gdb_get_line_number "varz-almostfilled"]
13981 +gdb_continue_to_breakpoint "varz-almostfilled"
13982 +# GCC uses the pointer type here, Intel Fortran Compiler 10.1.008 does not.
13983 +gdb_test "ptype varz" "type = (PTR TO -> \\( )?real(\\(kind=4\\)|\\*4) \\(\\*\\)\\)?"
13984 +# Intel Fortran Compiler 10.1.008 has a bug here - (2:11,7:7)
13985 +# as it produces DW_AT_lower_bound == DW_AT_upper_bound == 7.
13986 +gdb_test "ptype vart" "type = (PTR TO -> \\( )?real(\\(kind=4\\)|\\*4) \\(2:11,7:\\*\\)\\)?"
13987 +gdb_test "p varz" "\\$\[0-9\]* = \\(\\)"
13988 +gdb_test "p vart" "\\$\[0-9\]* = \\(\\)"
13989 +gdb_test "p varz(3)" "\\$\[0-9\]* = 4"
13990 +# maps to foo::vary(1,1)
13991 +gdb_test "p vart(2,7)" "\\$\[0-9\]* = 8"
13992 +# maps to foo::vary(2,2)
13993 +gdb_test "p vart(3,8)" "\\$\[0-9\]* = 9"
13994 +# maps to foo::vary(1,3)
13995 +gdb_test "p vart(2,9)" "\\$\[0-9\]* = 10"
13996 diff --git a/gdb/testsuite/gdb.fortran/dynamic.f90 b/gdb/testsuite/gdb.fortran/dynamic.f90
13997 new file mode 100644
13998 index 0000000..0f43564
13999 --- /dev/null
14000 +++ b/gdb/testsuite/gdb.fortran/dynamic.f90
14001 @@ -0,0 +1,98 @@
14002 +! Copyright 2007 Free Software Foundation, Inc.
14003 +!
14004 +! This program is free software; you can redistribute it and/or modify
14005 +! it under the terms of the GNU General Public License as published by
14006 +! the Free Software Foundation; either version 2 of the License, or
14007 +! (at your option) any later version.
14008 +!
14009 +! This program is distributed in the hope that it will be useful,
14010 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
14011 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14012 +! GNU General Public License for more details.
14013 +!
14014 +! You should have received a copy of the GNU General Public License
14015 +! along with this program; if not, write to the Free Software
14016 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
14017 +!
14018 +! Ihis file is the Fortran source file for dynamic.exp.
14019 +! Original file written by Jakub Jelinek <jakub@redhat.com>.
14020 +! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
14021 +
14022 +subroutine baz
14023 +  real, target, allocatable :: varx (:, :, :)
14024 +  real, pointer :: varv (:, :, :)
14025 +  real, target :: varu (1, 2, 3)
14026 +  logical :: l
14027 +  allocate (varx (1:6, 5:15, 17:28))            ! varx-init
14028 +  l = allocated (varx)
14029 +  varx(:, :, :) = 6                             ! varx-allocated
14030 +  varx(1, 5, 17) = 7
14031 +  varx(2, 6, 18) = 8
14032 +  varx(6, 15, 28) = 9
14033 +  varv => varx                                  ! varx-filled
14034 +  l = associated (varv)
14035 +  varv(3, 7, 19) = 10                           ! varv-associated
14036 +  varv => null ()                               ! varv-filled
14037 +  l = associated (varv)
14038 +  deallocate (varx)                             ! varv-deassociated
14039 +  l = allocated (varx)
14040 +  varu(:, :, :) = 10                            ! varx-deallocated
14041 +  allocate (varv (1:6, 5:15, 17:28))
14042 +  l = associated (varv)
14043 +  varv(:, :, :) = 6
14044 +  varv(1, 5, 17) = 7
14045 +  varv(2, 6, 18) = 8
14046 +  varv(6, 15, 28) = 9
14047 +  deallocate (varv)
14048 +  l = associated (varv)
14049 +  varv => varu
14050 +  varv(1, 1, 1) = 6
14051 +  varv(1, 2, 3) = 7
14052 +  l = associated (varv)
14053 +end subroutine baz
14054 +subroutine foo (vary, varw)
14055 +  real :: vary (:, :)
14056 +  real :: varw (:, :, :)
14057 +  vary(:, :) = 4                                ! vary-passed
14058 +  vary(1, 1) = 8
14059 +  vary(2, 2) = 9
14060 +  vary(1, 3) = 10
14061 +  varw(:, :, :) = 5                             ! vary-filled
14062 +  varw(1, 1, 1) = 6
14063 +  varw(2, 2, 2) = 7                             ! varw-almostfilled
14064 +end subroutine foo
14065 +subroutine bar (varz, vart)
14066 +  real :: varz (*)
14067 +  real :: vart (2:11, 7:*)
14068 +  varz(1:3) = 4
14069 +  varz(2) = 5                                   ! varz-almostfilled
14070 +  vart(2,7) = vart(2,7)
14071 +end subroutine bar
14072 +program test
14073 +  interface
14074 +    subroutine foo (vary, varw)
14075 +    real :: vary (:, :)
14076 +    real :: varw (:, :, :)
14077 +    end subroutine
14078 +  end interface
14079 +  interface
14080 +    subroutine bar (varz, vart)
14081 +    real :: varz (*)
14082 +    real :: vart (2:11, 7:*)
14083 +    end subroutine
14084 +  end interface
14085 +  real :: x (10, 10), y (5), z(8, 8, 8)
14086 +  x(:,:) = 1
14087 +  y(:) = 2
14088 +  z(:,:,:) = 3
14089 +  call baz
14090 +  call foo (x, z(2:6, 4:7, 6:8))
14091 +  call bar (y, x)
14092 +  if (x (1, 1) .ne. 8 .or. x (2, 2) .ne. 9 .or. x (1, 2) .ne. 4) call abort
14093 +  if (x (1, 3) .ne. 10) call abort
14094 +  if (z (2, 4, 6) .ne. 6 .or. z (3, 5, 7) .ne. 7 .or. z (2, 4, 7) .ne. 5) call abort
14095 +  if (any (y .ne. (/4, 5, 4, 2, 2/))) call abort
14096 +  call foo (transpose (x), z)
14097 +  if (x (1, 1) .ne. 8 .or. x (2, 2) .ne. 9 .or. x (1, 2) .ne. 4) call abort
14098 +  if (x (3, 1) .ne. 10) call abort
14099 +end
14100 diff --git a/gdb/testsuite/gdb.fortran/string.exp b/gdb/testsuite/gdb.fortran/string.exp
14101 new file mode 100644
14102 index 0000000..b1120c3
14103 --- /dev/null
14104 +++ b/gdb/testsuite/gdb.fortran/string.exp
14105 @@ -0,0 +1,59 @@
14106 +# Copyright 2008 Free Software Foundation, Inc.
14107 +
14108 +# This program is free software; you can redistribute it and/or modify
14109 +# it under the terms of the GNU General Public License as published by
14110 +# the Free Software Foundation; either version 2 of the License, or
14111 +# (at your option) any later version.
14112 +# 
14113 +# This program is distributed in the hope that it will be useful,
14114 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
14115 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14116 +# GNU General Public License for more details.
14117 +# 
14118 +# You should have received a copy of the GNU General Public License
14119 +# along with this program; if not, write to the Free Software
14120 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
14121 +
14122 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
14123 +
14124 +# This file is part of the gdb testsuite.  It contains tests for Fortran
14125 +# strings with dynamic length.
14126 +
14127 +set testfile "string"
14128 +set srcfile ${testfile}.f90
14129 +set binfile ${objdir}/${subdir}/${testfile}
14130 +
14131 +if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f77 quiet}] != "" } {
14132 +    untested "Couldn't compile ${srcfile}"
14133 +    return -1
14134 +}
14135 +
14136 +gdb_exit
14137 +gdb_start
14138 +gdb_reinitialize_dir $srcdir/$subdir
14139 +gdb_load ${binfile}
14140 +
14141 +if ![runto MAIN__] then {
14142 +    perror "couldn't run to breakpoint MAIN__"
14143 +    continue
14144 +}
14145 +
14146 +gdb_breakpoint [gdb_get_line_number "var-init"]
14147 +gdb_continue_to_breakpoint "var-init"
14148 +gdb_test "ptype c" "type = character(\\(kind=1\\)|\\*1)"
14149 +gdb_test "ptype d" "type = character(\\(kind=8\\)|\\*8)"
14150 +gdb_test "ptype e" "type = character(\\(kind=4\\)|\\*4)"
14151 +gdb_test "ptype f" "type = character(\\(kind=4\\)|\\*4) \\(7,8:10\\)"
14152 +gdb_test "ptype *e" "Attempt to take contents of a non-pointer value."
14153 +gdb_test "ptype *f" "type = character(\\(kind=4\\)|\\*4) \\(7\\)"
14154 +gdb_test "p c" "\\$\[0-9\]* = 'c'"
14155 +gdb_test "p d" "\\$\[0-9\]* = 'd       '"
14156 +gdb_test "p e" "\\$\[0-9\]* = 'g   '"
14157 +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   '\\) \\)"
14158 +gdb_test "p *e" "Attempt to take contents of a non-pointer value."
14159 +gdb_test "p *f" "Attempt to take contents of a non-pointer value."
14160 +
14161 +gdb_breakpoint [gdb_get_line_number "var-finish"]
14162 +gdb_continue_to_breakpoint "var-finish"
14163 +gdb_test "p e" "\\$\[0-9\]* = 'e   '" "p e re-set"
14164 +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"
14165 diff --git a/gdb/testsuite/gdb.fortran/string.f90 b/gdb/testsuite/gdb.fortran/string.f90
14166 new file mode 100644
14167 index 0000000..226dc5d
14168 --- /dev/null
14169 +++ b/gdb/testsuite/gdb.fortran/string.f90
14170 @@ -0,0 +1,37 @@
14171 +! Copyright 2008 Free Software Foundation, Inc.
14172 +!
14173 +! This program is free software; you can redistribute it and/or modify
14174 +! it under the terms of the GNU General Public License as published by
14175 +! the Free Software Foundation; either version 2 of the License, or
14176 +! (at your option) any later version.
14177 +!
14178 +! This program is distributed in the hope that it will be useful,
14179 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
14180 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14181 +! GNU General Public License for more details.
14182 +!
14183 +! You should have received a copy of the GNU General Public License
14184 +! along with this program; if not, write to the Free Software
14185 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
14186 +!
14187 +! Ihis file is the Fortran source file for dynamic.exp.
14188 +! Original file written by Jakub Jelinek <jakub@redhat.com>.
14189 +! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
14190 +
14191 +subroutine foo (e, f)
14192 +  character (len=1) :: c
14193 +  character (len=8) :: d
14194 +  character (len=*) :: e
14195 +  character (len=*) :: f (1:7, 8:10)
14196 +  c = 'c'
14197 +  d = 'd'
14198 +  e = 'e'                                       ! var-init
14199 +  f = 'f'
14200 +  f(1,9) = 'f2'
14201 +  c = 'c'                                       ! var-finish
14202 +end subroutine foo
14203 +  character (len=4) :: g, h (1:7, 8:10)
14204 +  g = 'g'
14205 +  h = 'h'
14206 +  call foo (g, h)
14207 +end
14208 diff --git a/gdb/testsuite/gdb.gdb/selftest.exp b/gdb/testsuite/gdb.gdb/selftest.exp
14209 index fc8bccc..e053813 100644
14210 --- a/gdb/testsuite/gdb.gdb/selftest.exp
14211 +++ b/gdb/testsuite/gdb.gdb/selftest.exp
14212 @@ -92,6 +92,10 @@ proc do_steps_and_nexts {} {
14213                 set description "step over ttyarg initialization"
14214                 set command "step"
14215             }
14216 +           -re ".*python_script = 0.*$gdb_prompt $" {
14217 +               set description "step over python_script initialization"
14218 +               set command "step"
14219 +           }
14220             -re ".*pre_stat_chain = make_command_stats_cleanup.*$gdb_prompt $" {
14221                 set description "next over make_command_stats_cleanup and everything it calls"
14222                 set command "next"
14223 diff --git a/gdb/testsuite/gdb.java/jnpe.exp b/gdb/testsuite/gdb.java/jnpe.exp
14224 new file mode 100644
14225 index 0000000..55aa80d
14226 --- /dev/null
14227 +++ b/gdb/testsuite/gdb.java/jnpe.exp
14228 @@ -0,0 +1,74 @@
14229 +# Copyright 2009 Free Software Foundation, Inc.
14230 +
14231 +# This program is free software; you can redistribute it and/or modify
14232 +# it under the terms of the GNU General Public License as published by
14233 +# the Free Software Foundation; either version 3 of the License, or
14234 +# (at your option) any later version.
14235 +#
14236 +# This program is distributed in the hope that it will be useful,
14237 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
14238 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14239 +# GNU General Public License for more details.
14240 +#
14241 +# You should have received a copy of the GNU General Public License
14242 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
14243 +
14244 +if $tracelevel then {
14245 +  strace $tracelevel
14246 +}
14247 +
14248 +load_lib "java.exp"
14249 +
14250 +set testfile "jnpe"
14251 +set srcfile ${testfile}.java
14252 +set binfile ${objdir}/${subdir}/${testfile}
14253 +if  { [compile_java_from_source ${srcdir}/$subdir/${srcfile} ${binfile} "-g"] != "" } {
14254 +    untested "Couldn't compile ${srcdir}/$subdir/${srcfile}"
14255 +    return -1
14256 +}
14257 +
14258 +# Start with a fresh gdb.
14259 +
14260 +gdb_exit
14261 +gdb_start
14262 +gdb_reinitialize_dir $srcdir/$subdir
14263 +gdb_load ${binfile}
14264 +
14265 +set line [gdb_get_line_number "break here" $testfile.java]
14266 +gdb_test "break $testfile.java:$line" ""
14267 +
14268 +gdb_test "run" \
14269 +  "// break here.*" \
14270 +  "run java next-over-throw"
14271 +
14272 +# See whether we have the needed unwinder hooks.
14273 +set ok 1
14274 +gdb_test_multiple "print _Unwind_DebugHook" "check for unwinder hook in java" {
14275 +    -re "= .*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
14276 +       pass "check for unwinder hook in java"
14277 +    }
14278 +    -re "No symbol .* in current context.?\r\n$gdb_prompt $" {
14279 +       # Pass the test so we don't get bogus fails in the results.
14280 +       setup_xfail *-*-*
14281 +       fail "check for unwinder hook in java"
14282 +       set ok 0
14283 +    }
14284 +}
14285 +if {!$ok} {
14286 +    untested jnpe.exp
14287 +    return -1
14288 +}
14289 +
14290 +gdb_test "handle SIGSEGV nostop noprint" \
14291 +  "SIGSEGV.*fault" \
14292 +  "disable SIGSEGV for next-over-NPE"
14293 +
14294 +# The line where we stop differ according to gcj; check just we did not already
14295 +# execute the catch point.
14296 +
14297 +gdb_test "next" \
14298 +  "" \
14299 +  "next over NPE"
14300 +
14301 +gdb_breakpoint [gdb_get_line_number "catch point"]
14302 +gdb_continue_to_breakpoint "catch point" ".*// catch point.*"
14303 diff --git a/gdb/testsuite/gdb.java/jnpe.java b/gdb/testsuite/gdb.java/jnpe.java
14304 new file mode 100644
14305 index 0000000..3524830
14306 --- /dev/null
14307 +++ b/gdb/testsuite/gdb.java/jnpe.java
14308 @@ -0,0 +1,38 @@
14309 +// Test next-over-NPE.
14310 +/* This testcase is part of GDB, the GNU debugger.
14311 +
14312 +   Copyright 2009 Free Software Foundation, Inc.
14313 +
14314 +   This program is free software; you can redistribute it and/or modify
14315 +   it under the terms of the GNU General Public License as published by
14316 +   the Free Software Foundation; either version 3 of the License, or
14317 +   (at your option) any later version.
14318 +
14319 +   This program is distributed in the hope that it will be useful,
14320 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
14321 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14322 +   GNU General Public License for more details.
14323 +
14324 +   You should have received a copy of the GNU General Public License
14325 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.
14326 +   */
14327 +
14328 +public class jnpe
14329 +{
14330 +  public static String npe ()
14331 +  {
14332 +    return ((Object) null).toString();
14333 +  }
14334 +
14335 +  public static void main (String[] args)
14336 +  {
14337 +    try
14338 +      {
14339 +       System.out.println (npe ()); // break here
14340 +      }
14341 +    catch (NullPointerException n)
14342 +      {
14343 +       System.out.println ("success"); // catch point
14344 +      }
14345 +  }
14346 +}
14347 diff --git a/gdb/testsuite/gdb.opt/array-from-register-func.c b/gdb/testsuite/gdb.opt/array-from-register-func.c
14348 new file mode 100644
14349 index 0000000..729f457
14350 --- /dev/null
14351 +++ b/gdb/testsuite/gdb.opt/array-from-register-func.c
14352 @@ -0,0 +1,22 @@
14353 +/* This file is part of GDB, the GNU debugger.
14354 +
14355 +   Copyright 2009 Free Software Foundation, Inc.
14356 +
14357 +   This program is free software; you can redistribute it and/or modify
14358 +   it under the terms of the GNU General Public License as published by
14359 +   the Free Software Foundation; either version 3 of the License, or
14360 +   (at your option) any later version.
14361 +
14362 +   This program is distributed in the hope that it will be useful,
14363 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
14364 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14365 +   GNU General Public License for more details.
14366 +
14367 +   You should have received a copy of the GNU General Public License
14368 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
14369 +
14370 +int
14371 +func (int *arr)
14372 +{
14373 +  return arr[0];
14374 +}
14375 diff --git a/gdb/testsuite/gdb.opt/array-from-register.c b/gdb/testsuite/gdb.opt/array-from-register.c
14376 new file mode 100644
14377 index 0000000..3090e7e
14378 --- /dev/null
14379 +++ b/gdb/testsuite/gdb.opt/array-from-register.c
14380 @@ -0,0 +1,28 @@
14381 +/* This file is part of GDB, the GNU debugger.
14382 +
14383 +   Copyright 2009 Free Software Foundation, Inc.
14384 +
14385 +   This program is free software; you can redistribute it and/or modify
14386 +   it under the terms of the GNU General Public License as published by
14387 +   the Free Software Foundation; either version 3 of the License, or
14388 +   (at your option) any later version.
14389 +
14390 +   This program is distributed in the hope that it will be useful,
14391 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
14392 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14393 +   GNU General Public License for more details.
14394 +
14395 +   You should have received a copy of the GNU General Public License
14396 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
14397 +
14398 +extern int func (int *arr);
14399 +
14400 +int
14401 +main (void)
14402 +{
14403 +  int arr[] = { 42 };
14404 +
14405 +  func (arr);
14406 +
14407 +  return 0;
14408 +}
14409 diff --git a/gdb/testsuite/gdb.opt/array-from-register.exp b/gdb/testsuite/gdb.opt/array-from-register.exp
14410 new file mode 100644
14411 index 0000000..f2de718
14412 --- /dev/null
14413 +++ b/gdb/testsuite/gdb.opt/array-from-register.exp
14414 @@ -0,0 +1,33 @@
14415 +# Copyright 2009 Free Software Foundation, Inc.
14416 +#
14417 +# This program is free software; you can redistribute it and/or modify
14418 +# it under the terms of the GNU General Public License as published by
14419 +# the Free Software Foundation; either version 2 of the License, or
14420 +# (at your option) any later version.
14421 +#
14422 +# This program is distributed in the hope that it will be useful,
14423 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
14424 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14425 +# GNU General Public License for more details.
14426 +#
14427 +# You should have received a copy of the GNU General Public License
14428 +# along with this program; if not, write to the Free Software
14429 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
14430 +#
14431 +# This file is part of the gdb testsuite.
14432 +
14433 +if { [prepare_for_testing array-from-register.exp "array-from-register"      \
14434 +                         {array-from-register.c array-from-register-func.c} \
14435 +                         {debug optimize=-O2}] } {
14436 +    return -1
14437 +}
14438 +
14439 +if ![runto func] then {
14440 +    return -1
14441 +}
14442 +
14443 +gdb_test "p arr" "\\$\[0-9\]+ = \\(int \\*\\) *0x\[0-9a-f\]+"
14444 +
14445 +# Seen regression:
14446 +# Address requested for identifier "arr" which is in register $rdi
14447 +gdb_test "p arr\[0\]" "\\$\[0-9\]+ = 42"
14448 diff --git a/gdb/testsuite/gdb.opt/fortran-string.exp b/gdb/testsuite/gdb.opt/fortran-string.exp
14449 new file mode 100644
14450 index 0000000..f997eec
14451 --- /dev/null
14452 +++ b/gdb/testsuite/gdb.opt/fortran-string.exp
14453 @@ -0,0 +1,41 @@
14454 +# Copyright 2009 Free Software Foundation, Inc.
14455 +
14456 +# This program is free software; you can redistribute it and/or modify
14457 +# it under the terms of the GNU General Public License as published by
14458 +# the Free Software Foundation; either version 2 of the License, or
14459 +# (at your option) any later version.
14460 +# 
14461 +# This program is distributed in the hope that it will be useful,
14462 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
14463 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14464 +# GNU General Public License for more details.
14465 +# 
14466 +# You should have received a copy of the GNU General Public License
14467 +# along with this program; if not, write to the Free Software
14468 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
14469 +
14470 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
14471 +
14472 +# Test GDB can cope with Fortran strings having their length present in a CPU
14473 +# register.  With -O0 the string length is passed on the stack.  To make this
14474 +# test meaningful the follow assertion should pass.  It is not being checked
14475 +# here as the "_s" symbol is compiler dependent:
14476 +#   (gdb) info address _s
14477 +#   Symbol "_s" is a variable in register XX.
14478 +
14479 +set test fortran-string
14480 +set srcfile ${test}.f90
14481 +if { [prepare_for_testing ${test}.exp ${test} ${srcfile} {debug f77 additional_flags=-O2}] } {
14482 +    return -1
14483 +}
14484 +
14485 +if ![runto MAIN__] then {
14486 +    perror "couldn't run to breakpoint MAIN__"
14487 +    continue
14488 +}
14489 +
14490 +gdb_breakpoint [gdb_get_line_number "s = s"]
14491 +gdb_continue_to_breakpoint "s = s"
14492 +gdb_test "frame" ".*s='foo'.*"
14493 +gdb_test "ptype s" "type = character\\*3"
14494 +gdb_test "p s" "\\$\[0-9\]* = 'foo'"
14495 diff --git a/gdb/testsuite/gdb.opt/fortran-string.f90 b/gdb/testsuite/gdb.opt/fortran-string.f90
14496 new file mode 100644
14497 index 0000000..e48d520
14498 --- /dev/null
14499 +++ b/gdb/testsuite/gdb.opt/fortran-string.f90
14500 @@ -0,0 +1,28 @@
14501 +! Copyright 2009 Free Software Foundation, Inc.
14502 +!
14503 +! This program is free software; you can redistribute it and/or modify
14504 +! it under the terms of the GNU General Public License as published by
14505 +! the Free Software Foundation; either version 2 of the License, or
14506 +! (at your option) any later version.
14507 +!
14508 +! This program is distributed in the hope that it will be useful,
14509 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
14510 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14511 +! GNU General Public License for more details.
14512 +!
14513 +! You should have received a copy of the GNU General Public License
14514 +! along with this program; if not, write to the Free Software
14515 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
14516 +!
14517 +! Ihis file is the Fortran source file for dynamic.exp.
14518 +! Original file written by Jakub Jelinek <jakub@redhat.com>.
14519 +! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
14520 +
14521 +  subroutine f(s)
14522 +  character*(*) s
14523 +  s = s
14524 +  end
14525 +
14526 +  program main
14527 +  call f ('foo')
14528 +  end
14529 diff --git a/gdb/testsuite/gdb.pascal/arrays.exp b/gdb/testsuite/gdb.pascal/arrays.exp
14530 new file mode 100644
14531 index 0000000..ccc6e1e
14532 --- /dev/null
14533 +++ b/gdb/testsuite/gdb.pascal/arrays.exp
14534 @@ -0,0 +1,104 @@
14535 +# Copyright 2008, 2009 Free Software Foundation, Inc.
14536 +#
14537 +# This program is free software; you can redistribute it and/or modify
14538 +# it under the terms of the GNU General Public License as published by
14539 +# the Free Software Foundation; either version 3 of the License, or
14540 +# (at your option) any later version.
14541 +#
14542 +# This program is distributed in the hope that it will be useful,
14543 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
14544 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14545 +# GNU General Public License for more details.
14546 +#
14547 +# You should have received a copy of the GNU General Public License
14548 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
14549 +
14550 +if $tracelevel then {
14551 +    strace $tracelevel
14552 +}
14553 +
14554 +load_lib "pascal.exp"
14555 +
14556 +set testfile "arrays"
14557 +set srcfile ${testfile}.pas
14558 +set binfile ${objdir}/${subdir}/${testfile}$EXEEXT
14559 +
14560 +# These tests only work with fpc, using the -gw3 compile-option
14561 +pascal_init
14562 +if { $pascal_compiler_is_fpc != 1 } {
14563 +  return -1
14564 +}
14565 +
14566 +# Detect if the fpc version is below 2.3.0
14567 +set fpc_generates_dwarf_for_dynamic_arrays 1
14568 +if { ($fpcversion_major < 2) || ( ($fpcversion_major == 2) && ($fpcversion_minor < 3))}  {
14569 +  set fpc_generates_dwarf_for_dynamic_arrays 0
14570 +}
14571 +
14572 +
14573 +if {[gdb_compile_pascal "-gw3 ${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug ]] != "" } {
14574 +  return -1
14575 +}
14576 +
14577 +gdb_exit
14578 +gdb_start
14579 +gdb_reinitialize_dir $srcdir/$subdir
14580 +gdb_load ${binfile}
14581 +set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
14582 +set bp_location2 [gdb_get_line_number "set breakpoint 2 here"]
14583 +
14584 +
14585 +if { [gdb_breakpoint ${srcfile}:${bp_location1}] } {
14586 +    pass "setting breakpoint 1"
14587 +}
14588 +if { [gdb_breakpoint ${srcfile}:${bp_location2}] } {
14589 +    pass "setting breakpoint 2"
14590 +}
14591 +
14592 +# Verify that "start" lands inside the right procedure.
14593 +if { [gdb_start_cmd] < 0 } {
14594 +    untested start
14595 +    return -1
14596 +}
14597 +
14598 +gdb_test "" ".* at .*${srcfile}.*" "start"
14599 +
14600 +gdb_test "cont" "Breakpoint .*:${bp_location1}.*" "Going to first breakpoint"
14601 +
14602 +gdb_test "print StatArrInt" ".* = \\{50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61\\}" "Print static array of integer type"
14603 +gdb_test "print StatArrInt_" ".* = \\{50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61\\}" "Print static array of integer"
14604 +
14605 +gdb_test "cont" "Breakpoint .*:${bp_location2}.*" "Going to second breakpoint"
14606 +
14607 +gdb_test "print StatArrChar" ".* = 'abcdefghijkl'" "Print static array of char"
14608 +gdb_test "print Stat2dArrInt" ".* = \\{\\{0, 1, 2, 3, 4\\}, \\{1, 2, 3, 4, 5\\}, \\{2, 3, 4, 5, 6\\}, \\{3, 4, 5, 6, 7\\}, \\{4, 5, 6, 7, 8\\}, \\{5, 6, 7, 8, 9\\}, \\{6, 7, 8, 9, 10\\}, \\{7, 8, 9, 10, 11\\}, \\{8, 9, 10, 11, 12\\}, \\{9, 10, 11, 12, 13\\}, \\{10, 11, 12, 13, 14\\}, \\{11, 12, 13, 14, 15\\}\\}" "Print static 2-dimensional array of integer"
14609 +
14610 +if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
14611 +  setup_xfail "*-*-*"
14612 +}
14613 +gdb_test "print DynArrInt" ".* = \\{50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62\\}" "Print dynamic array of integer type"
14614 +if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
14615 +  setup_xfail "*-*-*"
14616 +}
14617 +gdb_test "print DynArrInt_" ".* = \\{50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62\\}" "Print dynamic array of integer"
14618 +
14619 +if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
14620 +  setup_xfail "*-*-*"
14621 +}
14622 +gdb_test "print s" ".* = 'test'#0'string'" "Print string containing null-char"
14623 +
14624 +if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
14625 +  setup_xfail "*-*-*"
14626 +}
14627 +gdb_test "print DynArrStr" ".* = \\{'dstr0', 'dstr1', 'dstr2', 'dstr3', 'dstr4', 'dstr5', 'dstr6', 'dstr7', 'dstr8', 'dstr9', 'dstr10', 'dstr11', 'dstr12'\\}" "Print dynamic array of string"
14628 +
14629 +if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
14630 +  setup_xfail "*-*-*"
14631 +}
14632 +gdb_test "print StatArrStr" ".* = \\{'str0', 'str1', 'str2', 'str3', 'str4', 'str5', 'str6', 'str7', 'str8', 'str9', 'str10', 'str11', 'str12'\\}" "Print static array of string"
14633 +
14634 +if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
14635 +  setup_xfail "*-*-*"
14636 +}
14637 +gdb_test "print DynArrChar" ".* = 'abcdefghijklm'" "Print dynamic array of char"
14638 +
14639 diff --git a/gdb/testsuite/gdb.pascal/arrays.pas b/gdb/testsuite/gdb.pascal/arrays.pas
14640 new file mode 100644
14641 index 0000000..295602d
14642 --- /dev/null
14643 +++ b/gdb/testsuite/gdb.pascal/arrays.pas
14644 @@ -0,0 +1,82 @@
14645 +{
14646 + Copyright 2008, 2009 Free Software Foundation, Inc.
14647 +
14648 + This program is free software; you can redistribute it and/or modify
14649 + it under the terms of the GNU General Public License as published by
14650 + the Free Software Foundation; either version 3 of the License, or
14651 + (at your option) any later version.
14652 +
14653 + This program is distributed in the hope that it will be useful,
14654 + but WITHOUT ANY WARRANTY; without even the implied warranty of
14655 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14656 + GNU General Public License for more details.
14657 +
14658 + You should have received a copy of the GNU General Public License
14659 + along with this program.  If not, see <http://www.gnu.org/licenses/>.
14660 +}
14661 +
14662 +program arrays;
14663 +
14664 +{$mode objfpc}{$h+}
14665 +
14666 +uses sysutils;
14667 +
14668 +type TStatArrInt= array[0..11] of integer;
14669 +     TDynArrInt= array of integer;
14670 +     TStatArrStr= array[0..12] of string;
14671 +     TDynArrStr= array of string;
14672 +     TDynArrChar = array of char;
14673 +     TStatArrChar = array [0..11] of char;
14674 +
14675 +     TStat2dArrInt = array[0..11,0..4] of integer;
14676 +
14677 +var StatArrInt: TStatArrInt;
14678 +    StatArrInt_: Array[0..11] of integer;
14679 +    DynArrInt:  TDynArrInt;
14680 +    DynArrInt_: Array of integer;
14681 +    StatArrStr: TStatArrStr;
14682 +    DynArrStr: TDynArrStr;
14683 +    StatArrChar: TStatArrChar;
14684 +    DynArrChar: TDynArrChar;
14685 +
14686 +    Stat2dArrInt: TStat2dArrInt;
14687 +
14688 +    s: string;
14689 +       
14690 +    i,j : integer;
14691 +
14692 +begin
14693 +  for i := 0 to 11 do
14694 +    begin
14695 +    StatArrInt[i]:= i+50;
14696 +    StatArrInt_[i]:= i+50;
14697 +    StatArrChar[i]:= chr(ord('a')+i);
14698 +    for j := 0 to 4 do
14699 +      Stat2dArrInt[i,j]:=i+j;
14700 +    end;
14701 +  writeln(StatArrInt_[0]);
14702 +  writeln(StatArrInt[0]); { set breakpoint 1 here }
14703 +  writeln(StatArrChar[0]);
14704 +  writeln(Stat2dArrInt[0,0]);
14705 +
14706 +  setlength(DynArrInt,13);
14707 +  setlength(DynArrInt_,13);
14708 +  setlength(DynArrStr,13);
14709 +  setlength(DynArrChar,13);
14710 +  for i := 0 to 12 do
14711 +    begin
14712 +    DynArrInt[i]:= i+50;
14713 +    DynArrInt_[i]:= i+50;
14714 +    DynArrChar[i]:= chr(ord('a')+i);
14715 +    StatArrStr[i]:='str'+inttostr(i);
14716 +    DynArrStr[i]:='dstr'+inttostr(i);
14717 +    end;
14718 +  writeln(DynArrInt_[1]);
14719 +  writeln(DynArrInt[1]); 
14720 +  writeln(DynArrStr[1]); 
14721 +  writeln(StatArrStr[1]);
14722 +  writeln(DynArrChar[1]);
14723 +
14724 +  s := 'test'#0'string';
14725 +  writeln(s); { set breakpoint 2 here }
14726 +end.
14727 diff --git a/gdb/testsuite/gdb.python/py-cmd.exp b/gdb/testsuite/gdb.python/py-cmd.exp
14728 index 0f250d2..84e5038 100644
14729 --- a/gdb/testsuite/gdb.python/py-cmd.exp
14730 +++ b/gdb/testsuite/gdb.python/py-cmd.exp
14731 @@ -20,24 +20,6 @@ if $tracelevel then {
14732      strace $tracelevel
14733  }
14734  
14735 -# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}...
14736 -# Run a test named NAME, consisting of multiple lines of input.
14737 -# After each input line INPUT, search for result line RESULT.
14738 -# Succeed if all results are seen; fail otherwise.
14739 -proc gdb_py_test_multiple {name args} {
14740 -    global gdb_prompt
14741 -    foreach {input result} $args {
14742 -       if {[gdb_test_multiple $input "$name - $input" {
14743 -           -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
14744 -               pass "$name - $input"
14745 -           }
14746 -       }]} {
14747 -           return 1
14748 -       }
14749 -    }
14750 -    return 0
14751 -}
14752 -
14753  # Start with a fresh gdb.
14754  
14755  gdb_exit
14756 diff --git a/gdb/testsuite/gdb.python/py-frame.exp b/gdb/testsuite/gdb.python/py-frame.exp
14757 index e1212d3..77f44f5 100644
14758 --- a/gdb/testsuite/gdb.python/py-frame.exp
14759 +++ b/gdb/testsuite/gdb.python/py-frame.exp
14760 @@ -89,8 +89,6 @@ gdb_py_test_silent_cmd "python f0 = f1.newer ()" "get first frame" 0
14761  
14762  gdb_test "python print 'result =', f0 == f1" " = False" "test equality comparison (false)"
14763  gdb_test "python print 'result =', f0 == f0" " = True" "test equality comparison (true)"
14764 -gdb_test "python print 'result =', f0 != f1" " = True" "test inequality comparison (true)"
14765 -gdb_test "python print 'result =', f0 != f0" " = False" "test inequality comparison (false)"
14766  gdb_test "python print 'result =', f0.is_valid ()" " = True" "test Frame.is_valid"
14767  gdb_test "python print 'result =', f0.name ()" " = f2" "test Frame.name"
14768  gdb_test "python print 'result =', f0.type () == gdb.NORMAL_FRAME" " = True" "test Frame.type"
14769 @@ -105,3 +103,5 @@ gdb_test "python print 'result =', f0.read_var ('variable_which_surely_doesnt_ex
14770  gdb_test "python print 'result =', f0.read_var ('a')" " = 1" "test Frame.read_var - success"
14771  
14772  gdb_test "python print 'result =', gdb.selected_frame () == f1" " = True" "test gdb.selected_frame"
14773 +
14774 +gdb_test "python print 'result =', f0.block ()" "<gdb.Block object at 0x\[\[:xdigit:\]\]+>" "test Frame.block"
14775 diff --git a/gdb/testsuite/gdb.python/py-function.exp b/gdb/testsuite/gdb.python/py-function.exp
14776 index 38c5693..e7f0037 100644
14777 --- a/gdb/testsuite/gdb.python/py-function.exp
14778 +++ b/gdb/testsuite/gdb.python/py-function.exp
14779 @@ -20,24 +20,6 @@ if $tracelevel then {
14780      strace $tracelevel
14781  }
14782  
14783 -# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}...
14784 -# Run a test named NAME, consisting of multiple lines of input.
14785 -# After each input line INPUT, search for result line RESULT.
14786 -# Succeed if all results are seen; fail otherwise.
14787 -proc gdb_py_test_multiple {name args} {
14788 -    global gdb_prompt
14789 -    foreach {input result} $args {
14790 -       if {[gdb_test_multiple $input "$name - $input" {
14791 -           -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
14792 -               pass "$name - $input"
14793 -           }
14794 -       }]} {
14795 -           return 1
14796 -       }
14797 -    }
14798 -    return 0
14799 -}
14800 -
14801  # Start with a fresh gdb.
14802  
14803  gdb_exit
14804 diff --git a/gdb/testsuite/gdb.python/py-prettyprint.exp b/gdb/testsuite/gdb.python/py-prettyprint.exp
14805 index 3b2aadd..03bbf3e 100644
14806 --- a/gdb/testsuite/gdb.python/py-prettyprint.exp
14807 +++ b/gdb/testsuite/gdb.python/py-prettyprint.exp
14808 @@ -102,6 +102,8 @@ proc run_lang_tests {lang} {
14809      gdb_test "print estring" "\"embedded x\\\\201\\\\202\\\\203\\\\204\""
14810      gdb_test "print c" " = container \"container\" with 2 elements = {$nl *.0. = 23,$nl *.1. = 72$nl}"
14811  
14812 +    gdb_test "print nullstr" "RuntimeError: Error reading string from inferior.*"
14813 +
14814      gdb_test "print nstype" " = {$nl *.0. = 7,$nl *.1. = 42$nl}"
14815      gdb_test "continue" "Program exited normally\."
14816  
14817 diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp
14818 index a24bc11..e3043bc 100644
14819 --- a/gdb/testsuite/gdb.python/py-value.exp
14820 +++ b/gdb/testsuite/gdb.python/py-value.exp
14821 @@ -313,6 +313,15 @@ proc test_value_after_death {} {
14822      "print value's type"
14823  }
14824  
14825 +# Regression test for a cast failure.  The bug was that if we cast a
14826 +# value to its own type, gdb could crash.  This happened because we
14827 +# could end up double-freeing a struct value.
14828 +proc test_cast_regression {} {
14829 +  gdb_test "python v = gdb.Value(5)" "" "create value for cast test"
14830 +  gdb_test "python v = v.cast(v.type)" "" "cast value for cast test"
14831 +  gdb_test "python print v" "5" "print value for cast test"
14832 +}
14833 +
14834  # Regression test for invalid subscript operations.  The bug was that
14835  # the type of the value was not being checked before allowing a
14836  # subscript operation to proceed.
14837 @@ -437,6 +446,7 @@ if ![runto_main] then {
14838  test_value_in_inferior
14839  test_lazy_strings
14840  test_value_after_death
14841 +test_cast_regression
14842  
14843  # The following test recompiles the binary to test either C or C++
14844  # values. 
14845 diff --git a/gdb/testsuite/gdb.python/rh634108-solib_address.exp b/gdb/testsuite/gdb.python/rh634108-solib_address.exp
14846 new file mode 100644
14847 index 0000000..70319ff
14848 --- /dev/null
14849 +++ b/gdb/testsuite/gdb.python/rh634108-solib_address.exp
14850 @@ -0,0 +1,24 @@
14851 +# Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
14852 +
14853 +# This program is free software; you can redistribute it and/or modify
14854 +# it under the terms of the GNU General Public License as published by
14855 +# the Free Software Foundation; either version 3 of the License, or
14856 +# (at your option) any later version.
14857 +#
14858 +# This program is distributed in the hope that it will be useful,
14859 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
14860 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14861 +# GNU General Public License for more details.
14862 +#
14863 +# You should have received a copy of the GNU General Public License
14864 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
14865 +
14866 +# https://bugzilla.redhat.com/show_bug.cgi?id=634108
14867 +
14868 +gdb_exit
14869 +gdb_start
14870 +
14871 +# Skip all tests if Python scripting is not enabled.
14872 +if { [skip_python_tests] } { continue }
14873 +
14874 +gdb_test "python print gdb.solib_address(-1)" "None" "gdb.solib_address exists"
14875 diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork-forkoff.c b/gdb/testsuite/gdb.threads/watchpoint-fork-forkoff.c
14876 new file mode 100644
14877 index 0000000..4dc308b
14878 --- /dev/null
14879 +++ b/gdb/testsuite/gdb.threads/watchpoint-fork-forkoff.c
14880 @@ -0,0 +1,175 @@
14881 +/* Test case for forgotten hw-watchpoints after fork()-off of a process.
14882 +
14883 +   Copyright 2008, 2009 Free Software Foundation, Inc.
14884 +
14885 +   This file is part of GDB.
14886 +
14887 +   This program is free software; you can redistribute it and/or modify
14888 +   it under the terms of the GNU General Public License as published by
14889 +   the Free Software Foundation; either version 2 of the License, or
14890 +   (at your option) any later version.
14891 +
14892 +   This program is distributed in the hope that it will be useful,
14893 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
14894 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14895 +   GNU General Public License for more details.
14896 +
14897 +   You should have received a copy of the GNU General Public License
14898 +   along with this program; if not, write to the Free Software
14899 +   Foundation, Inc., 59 Temple Place - Suite 330,
14900 +   Boston, MA 02111-1307, USA.  */
14901 +
14902 +#include <string.h>
14903 +#include <errno.h>
14904 +
14905 +static void
14906 +delay (void)
14907 +{
14908 +  int i = usleep (1000000 / 100);
14909 +  assert (i == 0 || errno == EINTR);
14910 +}
14911 +
14912 +#if defined FOLLOW_PARENT
14913 +
14914 +static void
14915 +forkoff (int nr)
14916 +{
14917 +  pid_t child, pid_got;
14918 +  int exit_code = 42 + nr;
14919 +  int status, i;
14920 +
14921 +  child = fork ();
14922 +  switch (child)
14923 +    {
14924 +    case -1:
14925 +      assert (0);
14926 +    case 0:
14927 +      printf ("child%d: %d\n", nr, (int) getpid ());
14928 +      /* Delay to get both the "child%d" and "parent%d" message printed without
14929 +        a race breaking expect by its endless wait on `$gdb_prompt$':
14930 +        Breakpoint 3, breakpoint () at ../../../gdb/testsuite/gdb.threads/watchpoint-fork.c:33
14931 +        33      }
14932 +        (gdb) parent2: 14223  */
14933 +      i = sleep (1);
14934 +      assert (i == 0);
14935 +
14936 +      /* We must not get caught here (against a forgotten breakpoint).  */
14937 +      var++;
14938 +      breakpoint ();
14939 +
14940 +      _exit (exit_code);
14941 +    default:
14942 +      printf ("parent%d: %d\n", nr, (int) child);
14943 +      /* Delay to get both the "child%d" and "parent%d" message printed, see
14944 +        above.  */
14945 +      i = sleep (1);
14946 +      assert (i == 0);
14947 +
14948 +      pid_got = wait (&status);
14949 +      assert (pid_got == child);
14950 +      assert (WIFEXITED (status));
14951 +      assert (WEXITSTATUS (status) == exit_code);
14952 +
14953 +      /* We must get caught here (against a false watchpoint removal).  */
14954 +      breakpoint ();
14955 +    }
14956 +}
14957 +
14958 +#elif defined FOLLOW_CHILD
14959 +
14960 +static volatile int usr1_got;
14961 +
14962 +static void
14963 +handler_usr1 (int signo)
14964 +{
14965 +  usr1_got++;
14966 +}
14967 +
14968 +static void
14969 +forkoff (int nr)
14970 +{
14971 +  pid_t child;
14972 +  int i, loop;
14973 +  struct sigaction act, oldact;
14974 +#ifdef THREAD
14975 +  void *thread_result;
14976 +#endif
14977 +
14978 +  memset (&act, 0, sizeof act);
14979 +  act.sa_flags = SA_RESTART;
14980 +  act.sa_handler = handler_usr1;
14981 +  sigemptyset (&act.sa_mask);
14982 +  i = sigaction (SIGUSR1, &act, &oldact);
14983 +  assert (i == 0);
14984 +
14985 +  child = fork ();
14986 +  switch (child)
14987 +    {
14988 +    case -1:
14989 +      assert (0);
14990 +    default:
14991 +      printf ("parent%d: %d\n", nr, (int) child);
14992 +
14993 +      /* Sleep for a while to possibly get incorrectly ATTACH_THREADed by GDB
14994 +        tracing the child fork with no longer valid thread/lwp entries of the
14995 +        parent.  */
14996 +
14997 +      i = sleep (2);
14998 +      assert (i == 0);
14999 +
15000 +      /* We must not get caught here (against a forgotten breakpoint).  */
15001 +
15002 +      var++;
15003 +      breakpoint ();
15004 +
15005 +#ifdef THREAD
15006 +      /* And neither got caught our thread.  */
15007 +
15008 +      step = 99;
15009 +      i = pthread_join (thread, &thread_result);
15010 +      assert (i == 0);
15011 +      assert (thread_result == (void *) 99UL);
15012 +#endif
15013 +
15014 +      /* Be sure our child knows we did not get caught above.  */
15015 +
15016 +      i = kill (child, SIGUSR1);
15017 +      assert (i == 0);
15018 +
15019 +      /* Sleep for a while to check GDB's `info threads' no longer tracks us in
15020 +        the child fork.  */
15021 +
15022 +      i = sleep (2);
15023 +      assert (i == 0);
15024 +
15025 +      _exit (0);
15026 +    case 0:
15027 +      printf ("child%d: %d\n", nr, (int) getpid ());
15028 +
15029 +      /* Let the parent signal us about its success.  Be careful of races.  */
15030 +
15031 +      for (loop = 0; loop < 1000; loop++)
15032 +       {
15033 +         /* Parent either died (and USR1_GOT is zero) or it succeeded.  */
15034 +         if (kill (getppid (), 0) != 0)
15035 +           break;
15036 +         /* Parent succeeded?  */
15037 +         if (usr1_got)
15038 +           break;
15039 +
15040 +         delay ();
15041 +       }
15042 +      assert (usr1_got);
15043 +
15044 +      /* We must get caught here (against a false watchpoint removal).  */
15045 +
15046 +      breakpoint ();
15047 +    }
15048 +
15049 +  i = sigaction (SIGUSR1, &oldact, NULL);
15050 +  assert (i == 0);
15051 +}
15052 +
15053 +#else
15054 +# error "!FOLLOW_PARENT && !FOLLOW_CHILD"
15055 +#endif
15056 diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork-mt.c b/gdb/testsuite/gdb.threads/watchpoint-fork-mt.c
15057 new file mode 100644
15058 index 0000000..edacfc0
15059 --- /dev/null
15060 +++ b/gdb/testsuite/gdb.threads/watchpoint-fork-mt.c
15061 @@ -0,0 +1,157 @@
15062 +/* Test case for forgotten hw-watchpoints after fork()-off of a process.
15063 +
15064 +   Copyright 2008, 2009 Free Software Foundation, Inc.
15065 +
15066 +   This file is part of GDB.
15067 +
15068 +   This program is free software; you can redistribute it and/or modify
15069 +   it under the terms of the GNU General Public License as published by
15070 +   the Free Software Foundation; either version 2 of the License, or
15071 +   (at your option) any later version.
15072 +
15073 +   This program is distributed in the hope that it will be useful,
15074 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
15075 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15076 +   GNU General Public License for more details.
15077 +
15078 +   You should have received a copy of the GNU General Public License
15079 +   along with this program; if not, write to the Free Software
15080 +   Foundation, Inc., 59 Temple Place - Suite 330,
15081 +   Boston, MA 02111-1307, USA.  */
15082 +
15083 +#include <assert.h>
15084 +#include <unistd.h>
15085 +#include <sys/wait.h>
15086 +#include <stdio.h>
15087 +#include <stdlib.h>
15088 +#include <pthread.h>
15089 +
15090 +#include <asm/unistd.h>
15091 +#include <unistd.h>
15092 +#define gettid() syscall (__NR_gettid)
15093 +
15094 +/* Non-atomic `var++' should not hurt as we synchronize the threads by the STEP
15095 +   variable.  Hit-comments need to be duplicite there to catch both at-stops
15096 +   and behind-stops, depending on the target.  */
15097 +
15098 +static volatile int var;
15099 +
15100 +static void
15101 +dummy (void)
15102 +{
15103 +}
15104 +
15105 +static void
15106 +breakpoint (void)
15107 +{
15108 +}
15109 +
15110 +/* Include here the functions:
15111 +   static void forkoff (int nr);
15112 +   static void delay (void);  */
15113 +
15114 +static pthread_t thread;
15115 +static volatile int step;
15116 +#define THREAD
15117 +
15118 +#include "watchpoint-fork-forkoff.c"
15119 +
15120 +static void *
15121 +start (void *arg)
15122 +{
15123 +  if (step >= 3)
15124 +    goto step_3;
15125 +
15126 +  while (step != 1)
15127 +    delay ();
15128 +
15129 +  var++;       /* validity-thread-B */
15130 +  dummy ();    /* validity-thread-B */
15131 +  step = 2;
15132 +  while (step != 3)
15133 +    {
15134 +      if (step == 99)
15135 +       goto step_99;
15136 +      delay ();
15137 +    }
15138 +
15139 +step_3:
15140 +  if (step >= 5)
15141 +    goto step_5;
15142 +
15143 +  var++;       /* after-fork1-B */
15144 +  dummy ();    /* after-fork1-B */
15145 +  step = 4;
15146 +  while (step != 5)
15147 +    {
15148 +      if (step == 99)
15149 +       goto step_99;
15150 +      delay ();
15151 +    }
15152 +
15153 +step_5:
15154 +  var++;       /* after-fork2-B */
15155 +  dummy ();    /* after-fork2-B */
15156 +  return (void *) 5UL;
15157 +
15158 +step_99:
15159 +  /* We must not get caught here (against a forgotten breakpoint).  */
15160 +  var++;
15161 +  breakpoint ();
15162 +  return (void *) 99UL;
15163 +}
15164 +
15165 +int
15166 +main (void)
15167 +{
15168 +  int i;
15169 +  void *thread_result;
15170 +
15171 +  setbuf (stdout, NULL);
15172 +  printf ("main: %d\n", (int) gettid ());
15173 +
15174 +  /* General watchpoints validity.  */
15175 +  var++;       /* validity-first */
15176 +  dummy ();    /* validity-first */
15177 +
15178 +  i = pthread_create (&thread, NULL, start, NULL);
15179 +  assert (i == 0);
15180 +
15181 +  var++;       /* validity-thread-A */
15182 +  dummy ();    /* validity-thread-A */
15183 +  step = 1;
15184 +  while (step != 2)
15185 +    delay ();
15186 +
15187 +  /* Hardware watchpoints got disarmed here.  */
15188 +  forkoff (1);
15189 +
15190 +  var++;       /* after-fork1-A */
15191 +  dummy ();    /* after-fork1-A */
15192 +  step = 3;
15193 +#ifdef FOLLOW_CHILD
15194 +  /* Spawn new thread as it was deleted in the child of FORK.  */
15195 +  i = pthread_create (&thread, NULL, start, NULL);
15196 +  assert (i == 0);
15197 +#endif
15198 +  while (step != 4)
15199 +    delay ();
15200 +
15201 +  /* A sanity check for double hardware watchpoints removal.  */
15202 +  forkoff (2);
15203 +
15204 +  var++;       /* after-fork2-A */
15205 +  dummy ();    /* after-fork2-A */
15206 +  step = 5;
15207 +#ifdef FOLLOW_CHILD
15208 +  /* Spawn new thread as it was deleted in the child of FORK.  */
15209 +  i = pthread_create (&thread, NULL, start, NULL);
15210 +  assert (i == 0);
15211 +#endif
15212 +
15213 +  i = pthread_join (thread, &thread_result);
15214 +  assert (i == 0);
15215 +  assert (thread_result == (void *) 5UL);
15216 +
15217 +  return 0;
15218 +}
15219 diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork.c b/gdb/testsuite/gdb.threads/watchpoint-fork.c
15220 new file mode 100644
15221 index 0000000..5f62e7f
15222 --- /dev/null
15223 +++ b/gdb/testsuite/gdb.threads/watchpoint-fork.c
15224 @@ -0,0 +1,57 @@
15225 +/* Test case for forgotten hw-watchpoints after fork()-off of a process.
15226 +
15227 +   Copyright 2008, 2009 Free Software Foundation, Inc.
15228 +
15229 +   This file is part of GDB.
15230 +
15231 +   This program is free software; you can redistribute it and/or modify
15232 +   it under the terms of the GNU General Public License as published by
15233 +   the Free Software Foundation; either version 2 of the License, or
15234 +   (at your option) any later version.
15235 +
15236 +   This program is distributed in the hope that it will be useful,
15237 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
15238 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15239 +   GNU General Public License for more details.
15240 +
15241 +   You should have received a copy of the GNU General Public License
15242 +   along with this program; if not, write to the Free Software
15243 +   Foundation, Inc., 59 Temple Place - Suite 330,
15244 +   Boston, MA 02111-1307, USA.  */
15245 +
15246 +#include <assert.h>
15247 +#include <unistd.h>
15248 +#include <sys/wait.h>
15249 +#include <stdio.h>
15250 +#include <stdlib.h>
15251 +
15252 +static volatile int var;
15253 +
15254 +static void
15255 +breakpoint (void)
15256 +{
15257 +}
15258 +
15259 +/* Include here the function:
15260 +   static void forkoff (int nr);  */
15261 +
15262 +#include "watchpoint-fork-forkoff.c"
15263 +
15264 +int
15265 +main (void)
15266 +{
15267 +  setbuf (stdout, NULL);
15268 +  printf ("main: %d\n", (int) getpid ());
15269 +
15270 +  /* General watchpoints validity.  */
15271 +  var++;
15272 +  /* Hardware watchpoints got disarmed here.  */
15273 +  forkoff (1);
15274 +  /* This watchpoint got lost before.  */
15275 +  var++;
15276 +  /* A sanity check for double hardware watchpoints removal.  */
15277 +  forkoff (2);
15278 +  var++;
15279 +
15280 +  return 0;
15281 +}
15282 diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork.exp b/gdb/testsuite/gdb.threads/watchpoint-fork.exp
15283 new file mode 100644
15284 index 0000000..1dc93ab
15285 --- /dev/null
15286 +++ b/gdb/testsuite/gdb.threads/watchpoint-fork.exp
15287 @@ -0,0 +1,130 @@
15288 +# Copyright 2008, 2009 Free Software Foundation, Inc.
15289 +
15290 +# This program is free software; you can redistribute it and/or modify
15291 +# it under the terms of the GNU General Public License as published by
15292 +# the Free Software Foundation; either version 3 of the License, or
15293 +# (at your option) any later version.
15294 +#
15295 +# This program is distributed in the hope that it will be useful,
15296 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
15297 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15298 +# GNU General Public License for more details.
15299 +#
15300 +# You should have received a copy of the GNU General Public License
15301 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15302 +
15303 +# Test case for forgotten hw-watchpoints after fork()-off of a process.
15304 +
15305 +proc test {type symbol} {
15306 +    global objdir subdir srcdir
15307 +
15308 +    set test watchpoint-fork
15309 +
15310 +    global pf_prefix
15311 +    set prefix_test $pf_prefix
15312 +    lappend pf_prefix "$type:"
15313 +    set prefix_mt $pf_prefix
15314 +
15315 +    # no threads
15316 +
15317 +    set pf_prefix $prefix_mt
15318 +    lappend pf_prefix "singlethreaded:"
15319 +
15320 +    set executable ${test}-${type}
15321 +    if { [gdb_compile ${srcdir}/${subdir}/${test}.c ${objdir}/${subdir}/${executable} executable [list debug additional_flags=-D$symbol]] != "" } {
15322 +       untested ${test}.exp
15323 +       return -1
15324 +    }
15325 +    clean_restart $executable
15326 +
15327 +    gdb_test "show detach-on-fork" "Whether gdb will detach the child of a fork is on."
15328 +    gdb_test "set follow-fork-mode $type"
15329 +    gdb_test "show follow-fork-mode" "Debugger response to a program call of fork or vfork is \"$type\"."
15330 +    # Testcase uses it for the `follow-fork-mode child' type.
15331 +    gdb_test "handle SIGUSR1 nostop noprint pass"
15332 +
15333 +    if { ![runto_main] } then {
15334 +       gdb_suppress_tests
15335 +       return
15336 +    }
15337 +
15338 +    # Install the watchpoint only after getting into MAIN - workaround some PPC
15339 +    # problem.
15340 +    gdb_test "watch var" "atchpoint 2: var" "Set the watchpoint"
15341 +
15342 +    # It is never hit but it should not be left over in the fork()ed-off child.
15343 +    gdb_breakpoint "breakpoint"
15344 +
15345 +    gdb_test "continue" \
15346 +            "atchpoint 2: var.*Old value = 0.*New value = 1.*forkoff *\\(1\\).*" "watchpoints work"
15347 +    gdb_test "continue" \
15348 +            "reakpoint 3, breakpoint.*" "breakpoint after the first fork"
15349 +    gdb_test "continue" \
15350 +            "atchpoint 2: var.*Old value = 1.*New value = 2.*forkoff *\\(2\\).*" "watchpoint after the first fork"
15351 +    gdb_test "continue" \
15352 +            "reakpoint 3, breakpoint.*" "breakpoint after the second fork"
15353 +    gdb_test "continue" \
15354 +            "atchpoint 2: var.*Old value = 2.*New value = 3.*return *0;" "watchpoint after the second fork"
15355 +    gdb_test "continue" "Continuing..*Program exited normally." "finish"
15356 +
15357 +
15358 +    # threads
15359 +
15360 +    set pf_prefix $prefix_mt
15361 +    lappend pf_prefix "multithreaded:"
15362 +
15363 +    set executable ${test}-mt-${type}
15364 +    if { [gdb_compile_pthreads ${srcdir}/${subdir}/${test}-mt.c ${objdir}/${subdir}/${executable} executable [list debug additional_flags=-D$symbol]] != "" } {
15365 +       untested ${test}.exp
15366 +       return -1
15367 +    }
15368 +    clean_restart $executable
15369 +
15370 +    gdb_test "set follow-fork-mode $type"
15371 +    # Testcase uses it for the `follow-fork-mode child' type.
15372 +    gdb_test "handle SIGUSR1 nostop noprint pass"
15373 +
15374 +    if { ![runto_main] } then {
15375 +       gdb_suppress_tests
15376 +       return
15377 +    }
15378 +
15379 +    # Install the watchpoint only after getting into MAIN - workaround some PPC
15380 +    # problem.
15381 +    gdb_test "watch var" "atchpoint 2: var" "Set the watchpoint"
15382 +
15383 +    # It is never hit but it should not be left over in the fork()ed-off child.
15384 +    gdb_breakpoint "breakpoint"
15385 +
15386 +    gdb_test "continue" \
15387 +            "atchpoint 2: var.*Old value = 0.*New value = 1.*validity-first.*" "singlethread watchpoints work"
15388 +    gdb_test "continue" \
15389 +            "atchpoint 2: var.*Old value = 1.*New value = 2.*validity-thread-A.*" "multithreaded watchpoints work at A"
15390 +    gdb_test "continue" \
15391 +            "atchpoint 2: var.*Old value = 2.*New value = 3.*validity-thread-B.*" "multithreaded watchpoints work at B"
15392 +    gdb_test "continue" \
15393 +            "reakpoint 3, breakpoint.*" "breakpoint (A) after the first fork"
15394 +    gdb_test "continue" \
15395 +            "atchpoint 2: var.*Old value = 3.*New value = 4.*after-fork1-A.*" "watchpoint A after the first fork"
15396 +    gdb_test "continue" \
15397 +            "atchpoint 2: var.*Old value = 4.*New value = 5.*after-fork1-B.*" "watchpoint B after the first fork"
15398 +    gdb_test "continue" \
15399 +            "reakpoint 3, breakpoint.*" "breakpoint (A) after the second fork"
15400 +    gdb_test "continue" \
15401 +            "atchpoint 2: var.*Old value = 5.*New value = 6.*after-fork2-A.*" "watchpoint A after the second fork"
15402 +    gdb_test "continue" \
15403 +            "atchpoint 2: var.*Old value = 6.*New value = 7.*after-fork2-B.*" "watchpoint B after the second fork"
15404 +    gdb_test "continue" "Continuing..*Program exited normally." "finish"
15405 +
15406 +
15407 +    # cleanup
15408 +
15409 +    set pf_prefix $prefix_test
15410 +}
15411 +
15412 +test parent FOLLOW_PARENT
15413 +
15414 +# Only GNU/Linux is known to support `set follow-fork-mode child'.
15415 +if {[istarget "*-*-linux*"]} {
15416 +    test child FOLLOW_CHILD
15417 +}
15418 diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
15419 index 20e2fb7..b27d25c 100644
15420 --- a/gdb/testsuite/lib/gdb.exp
15421 +++ b/gdb/testsuite/lib/gdb.exp
15422 @@ -27,6 +27,7 @@ if {$tool == ""} {
15423  }
15424  
15425  load_lib libgloss.exp
15426 +load_lib python-support.exp
15427  
15428  global GDB
15429  
15430 diff --git a/gdb/testsuite/lib/pascal.exp b/gdb/testsuite/lib/pascal.exp
15431 index 9691bc1..13ea8b5 100644
15432 --- a/gdb/testsuite/lib/pascal.exp
15433 +++ b/gdb/testsuite/lib/pascal.exp
15434 @@ -37,6 +37,9 @@ proc pascal_init {} {
15435      global pascal_compiler_is_fpc
15436      global gpc_compiler
15437      global fpc_compiler
15438 +    global fpcversion_major
15439 +    global fpcversion_minor
15440 +    global fpcversion_release
15441      global env
15442   
15443      if { $pascal_init_done == 1 } {
15444 @@ -64,6 +67,20 @@ proc pascal_init {} {
15445             set pascal_compiler_is_fpc 1
15446             verbose -log "Free Pascal compiler found"
15447         }
15448 +
15449 +       # Detect the fpc-version
15450 +       if { $pascal_compiler_is_fpc == 1 } {
15451 +           set fpcversion_major 1
15452 +           set fpcversion_minor 0
15453 +           set fpcversion_release 0
15454 +           set fpcversion [ remote_exec host $fpc_compiler "-iV" ] 
15455 +           if [regexp {.*([0-9]+)\.([0-9]+)\.([0-9]+).?} $fpcversion] {
15456 +              regsub {.*([0-9]+)\.([0-9]+)\.([0-9]+).?\n?.?} $fpcversion {\1} fpcversion_major
15457 +              regsub {.*([0-9]+)\.([0-9]+)\.([0-9]+).?\n?.?} $fpcversion {\2} fpcversion_minor
15458 +              regsub {.*([0-9]+)\.([0-9]+)\.([0-9]+).?\n?.?} $fpcversion {\3} fpcversion_release
15459 +           }
15460 +            verbose -log "Freepascal version: $fpcversion_major.$fpcversion_minor.$fpcversion_release"
15461 +       }
15462      }
15463      set pascal_init_done 1
15464  }   
15465 diff --git a/gdb/testsuite/lib/python-support.exp b/gdb/testsuite/lib/python-support.exp
15466 new file mode 100644
15467 index 0000000..b8e9836
15468 --- /dev/null
15469 +++ b/gdb/testsuite/lib/python-support.exp
15470 @@ -0,0 +1,53 @@
15471 +global python_supported_saved
15472 +
15473 +# Return 1 if Python scripting is supported in GDB, 0 if not.
15474 +proc python_supported { } {
15475 +  global gdb_prompt
15476 +  global python_supported_saved
15477 +
15478 +  if [info exists python_supported_saved] {
15479 +      verbose "python_supported:  returning saved $python_supported_saved" 2
15480 +      return $python_supported_saved
15481 +  }
15482 +
15483 +  gdb_test_multiple "python print 'hello, world!'" "verify python support" {
15484 +    -re "not supported.*$gdb_prompt $" {
15485 +      return [set python_supported_saved 0]
15486 +    }
15487 +    -re "$gdb_prompt $"        {
15488 +      return [set python_supported_saved 1]
15489 +    }
15490 +  }
15491 +
15492 +  return [set python_supported_saved 0]
15493 +}
15494 +
15495 +# Run a command in GDB, and report a failure if a Python exception is thrown.
15496 +# If report_pass is true, report a pass if no exception is thrown.
15497 +proc gdb_py_test_silent_cmd {cmd name report_pass} {
15498 +  global gdb_prompt
15499 +
15500 +  gdb_test_multiple $cmd $name {
15501 +      -re "Traceback.*$gdb_prompt $"  { fail $name }
15502 +      -re "$gdb_prompt $"            { if $report_pass { pass $name } }
15503 +  }
15504 +}
15505 +
15506 +# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}...
15507 +# Run a test named NAME, consisting of multiple lines of input.
15508 +# After each input line INPUT, search for result line RESULT.
15509 +# Succeed if all results are seen; fail otherwise.
15510 +proc gdb_py_test_multiple {name args} {
15511 +    global gdb_prompt
15512 +
15513 +    foreach {input result} $args {
15514 +       if {[gdb_test_multiple $input "$name - $input" {
15515 +           -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
15516 +               pass "$name - $input"
15517 +           }
15518 +       }]} {
15519 +           return 1
15520 +       }
15521 +    }
15522 +    return 0
15523 +}
15524 diff --git a/gdb/thread.c b/gdb/thread.c
15525 index 0b291ba..ae3e4ff 100644
15526 --- a/gdb/thread.c
15527 +++ b/gdb/thread.c
15528 @@ -90,6 +90,16 @@ delete_step_resume_breakpoint (struct thread_info *tp)
15529      }
15530  }
15531  
15532 +void
15533 +delete_exception_resume_breakpoint (struct thread_info *tp)
15534 +{
15535 +  if (tp && tp->exception_resume_breakpoint)
15536 +    {
15537 +      delete_breakpoint (tp->exception_resume_breakpoint);
15538 +      tp->exception_resume_breakpoint = NULL;
15539 +    }
15540 +}
15541 +
15542  static void
15543  clear_thread_inferior_resources (struct thread_info *tp)
15544  {
15545 @@ -103,6 +113,12 @@ clear_thread_inferior_resources (struct thread_info *tp)
15546        tp->step_resume_breakpoint = NULL;
15547      }
15548  
15549 +  if (tp->exception_resume_breakpoint)
15550 +    {
15551 +      tp->exception_resume_breakpoint->disposition = disp_del_at_next_stop;
15552 +      tp->exception_resume_breakpoint = NULL;
15553 +    }
15554 +
15555    bpstat_clear (&tp->stop_bpstat);
15556  
15557    discard_all_intermediate_continuations_thread (tp);
15558 diff --git a/gdb/top.c b/gdb/top.c
15559 index b29e68d..8edac70 100644
15560 --- a/gdb/top.c
15561 +++ b/gdb/top.c
15562 @@ -337,6 +337,7 @@ void
15563  prepare_execute_command (void)
15564  {
15565    free_all_values ();
15566 +  free_all_types ();
15567  
15568    /* With multiple threads running while the one we're examining is stopped,
15569       the dcache can get stale without us being able to detect it.
15570 diff --git a/gdb/typeprint.c b/gdb/typeprint.c
15571 index ce9f551..5f9d739 100644
15572 --- a/gdb/typeprint.c
15573 +++ b/gdb/typeprint.c
15574 @@ -36,6 +36,7 @@
15575  #include "gdb_string.h"
15576  #include "exceptions.h"
15577  #include "valprint.h"
15578 +#include "dwarf2loc.h"
15579  #include <errno.h>
15580  
15581  extern void _initialize_typeprint (void);
15582 @@ -77,6 +78,9 @@ void
15583  type_print (struct type *type, char *varstring, struct ui_file *stream,
15584             int show)
15585  {
15586 +  if (show >= 0)
15587 +    type = check_typedef (type);
15588 +
15589    LA_PRINT_TYPE (type, varstring, stream, show, 0);
15590  }
15591  
15592 @@ -115,7 +119,8 @@ whatis_exp (char *exp, int show)
15593  {
15594    struct expression *expr;
15595    struct value *val;
15596 -  struct cleanup *old_chain = NULL;
15597 +  /* Required at least for the object_address_set call.  */
15598 +  struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
15599    struct type *real_type = NULL;
15600    struct type *type;
15601    int full = 0;
15602 @@ -126,12 +131,13 @@ whatis_exp (char *exp, int show)
15603    if (exp)
15604      {
15605        expr = parse_expression (exp);
15606 -      old_chain = make_cleanup (free_current_contents, &expr);
15607 +      make_cleanup (free_current_contents, &expr);
15608        val = evaluate_type (expr);
15609      }
15610    else
15611      val = access_value_history (0);
15612  
15613 +  object_address_set (value_raw_address (val));
15614    type = value_type (val);
15615  
15616    get_user_print_options (&opts);
15617 @@ -168,8 +174,7 @@ whatis_exp (char *exp, int show)
15618    type_print (type, "", gdb_stdout, show);
15619    printf_filtered ("\n");
15620  
15621 -  if (exp)
15622 -    do_cleanups (old_chain);
15623 +  do_cleanups (old_chain);
15624  }
15625  
15626  static void
15627 diff --git a/gdb/valarith.c b/gdb/valarith.c
15628 index 0c40905..a781636 100644
15629 --- a/gdb/valarith.c
15630 +++ b/gdb/valarith.c
15631 @@ -161,12 +161,26 @@ value_subscript (struct value *array, LONGEST index)
15632  
15633        get_discrete_bounds (range_type, &lowerbound, &upperbound);
15634        if (VALUE_LVAL (array) != lval_memory)
15635 -       return value_subscripted_rvalue (array, index, lowerbound);
15636 +       {
15637 +         if (index >= lowerbound && index <= upperbound)
15638 +           {
15639 +             CORE_ADDR element_size = TYPE_LENGTH (TYPE_TARGET_TYPE (tarray));
15640 +             CORE_ADDR offset = (index - lowerbound) * element_size;
15641 +
15642 +             return value_subscripted_rvalue (array, offset);
15643 +           }
15644 +         error (_("array or string index out of range"));
15645 +       }
15646  
15647        if (c_style == 0)
15648         {
15649           if (index >= lowerbound && index <= upperbound)
15650 -           return value_subscripted_rvalue (array, index, lowerbound);
15651 +           {
15652 +             CORE_ADDR element_size = TYPE_LENGTH (TYPE_TARGET_TYPE (tarray));
15653 +             CORE_ADDR offset = (index - lowerbound) * element_size;
15654 +
15655 +             return value_subscripted_rvalue (array, offset);
15656 +           }
15657           /* Emit warning unless we have an array of unknown size.
15658              An array of unknown size has lowerbound 0 and upperbound -1.  */
15659           if (upperbound > -1)
15660 @@ -185,34 +199,37 @@ value_subscript (struct value *array, LONGEST index)
15661      error (_("not an array or string"));
15662  }
15663  
15664 -/* Return the value of EXPR[IDX], expr an aggregate rvalue
15665 -   (eg, a vector register).  This routine used to promote floats
15666 -   to doubles, but no longer does.  */
15667 +/* Return the value of *((void *) ARRAY + ELEMENT), ARRAY an aggregate rvalue
15668 +   (eg, a vector register).  This routine used to promote floats to doubles,
15669 +   but no longer does.  OFFSET is zero-based with 0 for the lowermost existing
15670 +   element, it must be expressed in bytes (therefore multiplied by
15671 +   check_typedef (TYPE_TARGET_TYPE (array_type)).  */
15672  
15673  struct value *
15674 -value_subscripted_rvalue (struct value *array, LONGEST index, int lowerbound)
15675 +value_subscripted_rvalue (struct value *array, CORE_ADDR offset)
15676  {
15677    struct type *array_type = check_typedef (value_type (array));
15678    struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (array_type));
15679 -  unsigned int elt_size = TYPE_LENGTH (elt_type);
15680 -  unsigned int elt_offs = elt_size * longest_to_int (index - lowerbound);
15681    struct value *v;
15682  
15683 -  if (index < lowerbound || (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type)
15684 -                            && elt_offs >= TYPE_LENGTH (array_type)))
15685 -    error (_("no such vector element"));
15686 +  /* Do not check TYPE_LENGTH (array_type) as we may have been given the
15687 +     innermost dimension of a multi-dimensional Fortran array where its length
15688 +     is shorter than the possibly accessed element offset.  */
15689  
15690    v = allocate_value (elt_type);
15691    if (VALUE_LVAL (array) == lval_memory && value_lazy (array))
15692      set_value_lazy (v, 1);
15693    else
15694 -    memcpy (value_contents_writeable (v),
15695 -           value_contents (array) + elt_offs, elt_size);
15696 +    {
15697 +      unsigned int elt_size = TYPE_LENGTH (elt_type);
15698 +      memcpy (value_contents_writeable (v),
15699 +             value_contents (array) + offset, elt_size);
15700 +    }
15701  
15702    set_value_component_location (v, array);
15703    VALUE_REGNUM (v) = VALUE_REGNUM (array);
15704    VALUE_FRAME_ID (v) = VALUE_FRAME_ID (array);
15705 -  set_value_offset (v, value_offset (array) + elt_offs);
15706 +  set_value_offset (v, value_offset (array) + offset);
15707    return v;
15708  }
15709  
15710 @@ -292,6 +309,10 @@ int
15711  binop_user_defined_p (enum exp_opcode op,
15712                       struct value *arg1, struct value *arg2)
15713  {
15714 +  /* FIXME: We should support user defined ops for dynamic types.  */
15715 +  if (TYPE_DYNAMIC (value_type (arg1)) || TYPE_DYNAMIC (value_type (arg2)))
15716 +    return 0;
15717 +
15718    return binop_types_user_defined_p (op, value_type (arg1), value_type (arg2));
15719  }
15720  
15721 diff --git a/gdb/valops.c b/gdb/valops.c
15722 index 7fbad10..8e32405 100644
15723 --- a/gdb/valops.c
15724 +++ b/gdb/valops.c
15725 @@ -38,6 +38,7 @@
15726  #include "cp-support.h"
15727  #include "dfp.h"
15728  #include "user-regs.h"
15729 +#include "dwarf2loc.h"
15730  
15731  #include <errno.h>
15732  #include "gdb_string.h"
15733 @@ -858,6 +859,65 @@ value_one (struct type *type, enum lval_type lv)
15734    return val;
15735  }
15736  
15737 +/* object_address_set must be already called before this function.  */
15738 +
15739 +const char *
15740 +object_address_data_not_valid (struct type *type)
15741 +{
15742 +  /* Attributes are present only at the target type of a typedef.  Make the
15743 +     call conditional as it would otherwise loop through type_length_get.  */
15744 +  if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
15745 +    CHECK_TYPEDEF (type);
15746 +
15747 +  /* DW_AT_associated has a preference over DW_AT_allocated.  */
15748 +  if (TYPE_NOT_ASSOCIATED (type)
15749 +      || (TYPE_ASSOCIATED (type) != NULL
15750 +         && 0 == dwarf_locexpr_baton_eval (TYPE_ASSOCIATED (type))))
15751 +    return N_("object is not associated");
15752 +
15753 +  if (TYPE_NOT_ALLOCATED (type)
15754 +      || (TYPE_ALLOCATED (type) != NULL
15755 +         && 0 == dwarf_locexpr_baton_eval (TYPE_ALLOCATED (type))))
15756 +    return N_("object is not allocated");
15757 +
15758 +  return NULL;
15759 +}
15760 +
15761 +/* Return non-NULL check_typedef result on TYPE if the variable is valid.  If
15762 +   it is valid the function may store the data address (DW_AT_DATA_LOCATION) of
15763 +   TYPE at *ADDRESS_RETURN.  You must set *ADDRESS_RETURN from
15764 +   value_raw_address (VAL) before calling this function.  If no
15765 +   DW_AT_DATA_LOCATION is present for TYPE the address at *ADDRESS_RETURN is
15766 +   left unchanged.  ADDRESS_RETURN must not be NULL, use
15767 +   object_address_data_not_valid () for just the data validity check.  */
15768 +
15769 +struct type *
15770 +object_address_get_data (struct type *type, CORE_ADDR *address_return)
15771 +{
15772 +  gdb_assert (address_return != NULL);
15773 +
15774 +  object_address_set (*address_return);
15775 +
15776 +  /* TYPE_DATA_LOCATION_DWARF_BLOCK / TYPE_DATA_LOCATION_ADDR are present only
15777 +     at the target type of a typedef.  */
15778 +  CHECK_TYPEDEF (type);
15779 +
15780 +  if (object_address_data_not_valid (type) != NULL)
15781 +    {
15782 +      /* Do not try to evaluate DW_AT_data_location as it may even crash
15783 +        (it would just return the value zero in the gfortran case).  */
15784 +      return NULL;
15785 +    }
15786 +
15787 +  if (TYPE_DATA_LOCATION_IS_ADDR (type))
15788 +    *address_return = TYPE_DATA_LOCATION_ADDR (type);
15789 +  else if (TYPE_DATA_LOCATION_DWARF_BLOCK (type) != NULL)
15790 +    *address_return
15791 +      = dwarf_locexpr_baton_eval (TYPE_DATA_LOCATION_DWARF_BLOCK (type));
15792 +
15793 +  return type;
15794 +}
15795 +
15796  /* Helper function for value_at, value_at_lazy, and value_at_lazy_stack.  */
15797  
15798  static struct value *
15799 @@ -956,15 +1016,21 @@ value_fetch_lazy (struct value *val)
15800      }
15801    else if (VALUE_LVAL (val) == lval_memory)
15802      {
15803 -      CORE_ADDR addr = value_address (val);
15804 -      int length = TYPE_LENGTH (check_typedef (value_enclosing_type (val)));
15805 +      CORE_ADDR addr = value_raw_address (val);
15806  
15807 -      if (length)
15808 +      if (object_address_get_data (value_type (val), &addr))
15809         {
15810 -         if (value_stack (val))
15811 -           read_stack (addr, value_contents_all_raw (val), length);
15812 -         else
15813 -           read_memory (addr, value_contents_all_raw (val), length);
15814 +         struct type *type = value_enclosing_type (val);
15815 +         int length = TYPE_LENGTH (check_typedef (type));
15816 +
15817 +         if (length)
15818 +           {
15819 +             addr += value_offset (val);
15820 +             if (value_stack (val))
15821 +               read_stack (addr, value_contents_all_raw (val), length);
15822 +             else
15823 +               read_memory (addr, value_contents_all_raw (val), length);
15824 +           }
15825         }
15826      }
15827    else if (VALUE_LVAL (val) == lval_register)
15828 @@ -1374,7 +1440,18 @@ address_of_variable (struct symbol *var, struct block *b)
15829    if ((VALUE_LVAL (val) == lval_memory && value_lazy (val))
15830        || TYPE_CODE (type) == TYPE_CODE_FUNC)
15831      {
15832 -      CORE_ADDR addr = value_address (val);
15833 +      CORE_ADDR addr;
15834 +
15835 +      if (VALUE_LVAL (val) == lval_memory)
15836 +       {
15837 +         addr = value_raw_address (val);
15838 +         if (!object_address_get_data (type, &addr))
15839 +           error (_("Can't take address of memory lvalue \"%s\"."),
15840 +                  SYMBOL_PRINT_NAME (var));
15841 +         set_value_address (val, addr);
15842 +       }
15843 +
15844 +      addr = value_address (val);
15845  
15846        return value_from_pointer (lookup_pointer_type (type), addr);
15847      }
15848 @@ -1481,6 +1558,7 @@ struct value *
15849  value_coerce_array (struct value *arg1)
15850  {
15851    struct type *type = check_typedef (value_type (arg1));
15852 +  CORE_ADDR address;
15853  
15854    /* If the user tries to do something requiring a pointer with an
15855       array that has not yet been pushed to the target, then this would
15856 @@ -1490,8 +1568,12 @@ value_coerce_array (struct value *arg1)
15857    if (VALUE_LVAL (arg1) != lval_memory)
15858      error (_("Attempt to take address of value not located in memory."));
15859  
15860 +  address = value_raw_address (arg1);
15861 +  if (!object_address_get_data (type, &address))
15862 +    error (_("Attempt to take address of non-valid value."));
15863 +
15864    return value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
15865 -                            value_address (arg1));
15866 +                            address + value_offset (arg1));
15867  }
15868  
15869  /* Given a value which is a function, return a value which is a pointer
15870 diff --git a/gdb/valprint.c b/gdb/valprint.c
15871 index ad6268e..fb0ef7a 100644
15872 --- a/gdb/valprint.c
15873 +++ b/gdb/valprint.c
15874 @@ -36,6 +36,7 @@
15875  #include "dfp.h"
15876  #include "python/python.h"
15877  #include "ada-lang.h"
15878 +#include "dwarf2loc.h"
15879  
15880  #include <errno.h>
15881  
15882 @@ -237,7 +238,6 @@ scalar_type_p (struct type *type)
15883      case TYPE_CODE_STRUCT:
15884      case TYPE_CODE_UNION:
15885      case TYPE_CODE_SET:
15886 -    case TYPE_CODE_STRING:
15887      case TYPE_CODE_BITSTRING:
15888        return 0;
15889      default:
15890 @@ -1142,6 +1142,7 @@ val_print_array_elements (struct type *type, const gdb_byte *valaddr,
15891  {
15892    unsigned int things_printed = 0;
15893    unsigned len;
15894 +  struct type *saved_type = type;
15895    struct type *elttype, *index_type;
15896    unsigned eltlen;
15897    /* Position of the array element we are examining to see
15898 @@ -1150,9 +1151,33 @@ val_print_array_elements (struct type *type, const gdb_byte *valaddr,
15899    /* Number of repetitions we have detected so far.  */
15900    unsigned int reps;
15901    LONGEST low_bound_index = 0;
15902 +  struct cleanup *back_to;
15903 +  CORE_ADDR saved_address = address;
15904 +  
15905 +  back_to = make_cleanup (null_cleanup, 0);
15906 +  type = object_address_get_data (type, &address);
15907 +  if (!type)
15908 +    {
15909 +      fputs_filtered (object_address_data_not_valid (type), stream);
15910 +      do_cleanups (back_to);
15911 +      return;
15912 +    }
15913 +  if (address != saved_address)
15914 +    {
15915 +      size_t length = TYPE_LENGTH (type);
15916  
15917 -  elttype = TYPE_TARGET_TYPE (type);
15918 -  eltlen = TYPE_LENGTH (check_typedef (elttype));
15919 +      valaddr = xmalloc (length);
15920 +      make_cleanup (xfree, (gdb_byte *) valaddr);
15921 +      read_memory (address, (gdb_byte *) valaddr, length);
15922 +    }
15923 +
15924 +  /* Skip typedefs but do not resolve TYPE_DYNAMIC.  */
15925 +  elttype = saved_type;
15926 +  while (TYPE_CODE (elttype) == TYPE_CODE_TYPEDEF)
15927 +    elttype = TYPE_TARGET_TYPE (elttype);
15928 +  elttype = TYPE_TARGET_TYPE (elttype);
15929 +
15930 +  eltlen = TYPE_ARRAY_BYTE_STRIDE_VALUE (type);
15931    index_type = TYPE_INDEX_TYPE (type);
15932  
15933    /* Compute the number of elements in the array.  On most arrays,
15934 @@ -1160,9 +1185,6 @@ val_print_array_elements (struct type *type, const gdb_byte *valaddr,
15935       is simply the size of the array divided by the size of the elements.
15936       But for arrays of elements whose size is zero, we need to look at
15937       the bounds.  */
15938 -  if (eltlen != 0)
15939 -    len = TYPE_LENGTH (type) / eltlen;
15940 -  else
15941      {
15942        LONGEST low, hi;
15943  
15944 @@ -1236,6 +1258,8 @@ val_print_array_elements (struct type *type, const gdb_byte *valaddr,
15945      {
15946        fprintf_filtered (stream, "...");
15947      }
15948 +
15949 +  do_cleanups (back_to);
15950  }
15951  
15952  /* Read LEN bytes of target memory at address MEMADDR, placing the
15953 diff --git a/gdb/value.c b/gdb/value.c
15954 index d552402..b10269c 100644
15955 --- a/gdb/value.c
15956 +++ b/gdb/value.c
15957 @@ -39,6 +39,7 @@
15958  #include "objfiles.h"
15959  #include "valprint.h"
15960  #include "cli/cli-decode.h"
15961 +#include "observer.h"
15962  
15963  #include "python/python.h"
15964  
15965 @@ -828,12 +829,15 @@ void
15966  set_value_component_location (struct value *component,
15967                               const struct value *whole)
15968  {
15969 +  CORE_ADDR addr;
15970 +
15971    if (whole->lval == lval_internalvar)
15972      VALUE_LVAL (component) = lval_internalvar_component;
15973    else
15974      VALUE_LVAL (component) = whole->lval;
15975  
15976    component->location = whole->location;
15977 +
15978    if (whole->lval == lval_computed)
15979      {
15980        struct lval_funcs *funcs = whole->location.computed.funcs;
15981 @@ -841,6 +845,12 @@ set_value_component_location (struct value *component,
15982        if (funcs->copy_closure)
15983          component->location.computed.closure = funcs->copy_closure (whole);
15984      }
15985 +
15986 +  addr = value_raw_address (component);
15987 +  object_address_get_data (value_type (whole), &addr);
15988 +  if (component->lval != lval_internalvar
15989 +      && component->lval != lval_internalvar_component)
15990 +    set_value_address (component, addr);
15991  }
15992  
15993  \f
15994 @@ -973,6 +983,29 @@ show_values (char *num_exp, int from_tty)
15995        num_exp[1] = '\0';
15996      }
15997  }
15998 +
15999 +/* Sanity check for memory leaks and proper types reference counting.  */
16000 +
16001 +static void
16002 +value_history_cleanup (void *unused)
16003 +{
16004 +  while (value_history_chain)
16005 +    {
16006 +      struct value_history_chunk *chunk = value_history_chain;
16007 +      int i;
16008 +
16009 +      for (i = 0; i < ARRAY_SIZE (chunk->values); i++)
16010 +       value_free (chunk->values[i]);
16011 +
16012 +      value_history_chain = chunk->next;
16013 +      xfree (chunk);
16014 +    }
16015 +  value_history_count = 0;
16016 +
16017 +  /* Free the unreferenced types above.  */
16018 +  free_all_values ();
16019 +  free_all_types ();
16020 +}
16021  \f
16022  /* Internal variables.  These are variables within the debugger
16023     that hold values assigned by debugger commands.
16024 @@ -1451,6 +1484,40 @@ call_internal_function (struct gdbarch *gdbarch,
16025    return (*ifn->handler) (gdbarch, language, ifn->cookie, argc, argv);
16026  }
16027  
16028 +/* Call type_mark_used for any TYPEs referenced from this GDB source file.  */
16029 +
16030 +static void
16031 +value_types_mark_used (void)
16032 +{
16033 +  struct internalvar *var;
16034 +  struct value_history_chunk *chunk;
16035 +
16036 +  for (var = internalvars; var != NULL; var = var->next)
16037 +    switch (var->kind)
16038 +      {
16039 +      case INTERNALVAR_VALUE:
16040 +       type_mark_used (value_type (var->u.value));
16041 +       break;
16042 +
16043 +      case INTERNALVAR_INTEGER:
16044 +       type_mark_used (var->u.integer.type);
16045 +       break;
16046 +
16047 +      case INTERNALVAR_POINTER:
16048 +       type_mark_used (var->u.pointer.type);
16049 +       break;
16050 +      }
16051 +
16052 +  for (chunk = value_history_chain; chunk != NULL; chunk = chunk->next)
16053 +    {
16054 +      int i;
16055 +
16056 +      for (i = 0; i < ARRAY_SIZE (chunk->values); i++)
16057 +       if (chunk->values[i])
16058 +         type_mark_used (value_type (chunk->values[i]));
16059 +    }
16060 +}
16061 +
16062  /* The 'function' command.  This does nothing -- it is just a
16063     placeholder to let "help function NAME" work.  This is also used as
16064     the implementation of the sub-command that is created when
16065 @@ -1498,11 +1565,10 @@ preserve_one_value (struct value *value, struct objfile *objfile,
16066                     htab_t copied_types)
16067  {
16068    if (TYPE_OBJFILE (value->type) == objfile)
16069 -    value->type = copy_type_recursive (objfile, value->type, copied_types);
16070 +    value->type = copy_type_recursive (value->type, copied_types);
16071  
16072    if (TYPE_OBJFILE (value->enclosing_type) == objfile)
16073 -    value->enclosing_type = copy_type_recursive (objfile,
16074 -                                                value->enclosing_type,
16075 +    value->enclosing_type = copy_type_recursive (value->enclosing_type,
16076                                                  copied_types);
16077  }
16078  
16079 @@ -1517,13 +1583,13 @@ preserve_one_internalvar (struct internalvar *var, struct objfile *objfile,
16080      case INTERNALVAR_INTEGER:
16081        if (var->u.integer.type && TYPE_OBJFILE (var->u.integer.type) == objfile)
16082         var->u.integer.type
16083 -         = copy_type_recursive (objfile, var->u.integer.type, copied_types);
16084 +         = copy_type_recursive (var->u.integer.type, copied_types);
16085        break;
16086  
16087      case INTERNALVAR_POINTER:
16088        if (TYPE_OBJFILE (var->u.pointer.type) == objfile)
16089         var->u.pointer.type
16090 -         = copy_type_recursive (objfile, var->u.pointer.type, copied_types);
16091 +         = copy_type_recursive (var->u.pointer.type, copied_types);
16092        break;
16093  
16094      case INTERNALVAR_VALUE:
16095 @@ -2387,7 +2453,24 @@ value_from_decfloat (struct type *type, const gdb_byte *dec)
16096  struct value *
16097  coerce_ref (struct value *arg)
16098  {
16099 -  struct type *value_type_arg_tmp = check_typedef (value_type (arg));
16100 +  struct type *value_type_arg_tmp;
16101 +
16102 +  if (TYPE_DYNAMIC (value_type (arg)))
16103 +    {
16104 +      struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
16105 +      CORE_ADDR address;
16106 +
16107 +      value_type_arg_tmp = value_type (arg);
16108 +      address = value_raw_address (arg);
16109 +      value_type_arg_tmp = object_address_get_data (value_type_arg_tmp,
16110 +                                                   &address);
16111 +      if (! value_type_arg_tmp)
16112 +       error (_("Attempt to coerce non-valid value."));
16113 +      arg = value_at_lazy (value_type_arg_tmp, address);
16114 +      do_cleanups (cleanups);
16115 +    }
16116 +  else
16117 +    value_type_arg_tmp = check_typedef (value_type (arg));
16118  
16119    if (TYPE_CODE (value_type_arg_tmp) == TYPE_CODE_REF)
16120      arg = value_at_lazy (TYPE_TARGET_TYPE (value_type_arg_tmp),
16121 @@ -2485,4 +2568,8 @@ VARIABLE is already initialized."));
16122    add_prefix_cmd ("function", no_class, function_command, _("\
16123  Placeholder command for showing help on convenience functions."),
16124                   &functionlist, "function ", 0, &cmdlist);
16125 +
16126 +  make_final_cleanup (value_history_cleanup, NULL);
16127 +
16128 +  observer_attach_mark_used (value_types_mark_used);
16129  }
16130 diff --git a/gdb/value.h b/gdb/value.h
16131 index 12cbc0a..a508bf6 100644
16132 --- a/gdb/value.h
16133 +++ b/gdb/value.h
16134 @@ -372,6 +372,10 @@ extern struct value *value_from_double (struct type *type, DOUBLEST num);
16135  extern struct value *value_from_decfloat (struct type *type,
16136                                           const gdb_byte *decbytes);
16137  
16138 +extern const char *object_address_data_not_valid (struct type *type);
16139 +extern struct type *object_address_get_data (struct type *type,
16140 +                                            CORE_ADDR *address_return);
16141 +
16142  extern struct value *value_at (struct type *type, CORE_ADDR addr);
16143  extern struct value *value_at_lazy (struct type *type, CORE_ADDR addr);
16144  
16145 @@ -729,7 +733,7 @@ extern struct value *value_allocate_space_in_inferior (int);
16146  extern struct value *value_of_local (const char *name, int complain);
16147  
16148  extern struct value *value_subscripted_rvalue (struct value *array,
16149 -                                              LONGEST index, int lowerbound);
16150 +                                              CORE_ADDR offset);
16151  
16152  /* User function handler.  */
16153  
16154 diff --git a/gdb/varobj.c b/gdb/varobj.c
16155 index b9b8e91..a81d25c 100644
16156 --- a/gdb/varobj.c
16157 +++ b/gdb/varobj.c
16158 @@ -26,6 +26,8 @@
16159  #include "gdbcmd.h"
16160  #include "block.h"
16161  #include "valprint.h"
16162 +#include "objfiles.h"
16163 +#include "parser-defs.h"
16164  
16165  #include "gdb_assert.h"
16166  #include "gdb_string.h"
This page took 1.26993 seconds and 3 git commands to generate.