1 Index: gdb-7.2.90.20110525/gdb/dwarf2read.c
2 ===================================================================
3 --- gdb-7.2.90.20110525.orig/gdb/dwarf2read.c 2011-05-25 17:06:19.000000000 +0200
4 +++ gdb-7.2.90.20110525/gdb/dwarf2read.c 2011-05-25 17:10:46.000000000 +0200
5 @@ -7665,12 +7665,14 @@ read_set_type (struct die_info *die, str
6 return set_die_type (die, set_type, cu);
9 -/* First cut: install each common block member as a global variable. */
10 +/* Create appropriate locally-scoped variables for all the DW_TAG_common_block
11 + entries. Create also TYPE_CODE_STRUCT listing all such variables to be
12 + available for `info common'. COMMON_BLOCK_DOMAIN is used to sepate the
13 + common blocks name namespace from regular variable names. */
16 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
18 - struct die_info *child_die;
19 struct attribute *attr;
21 CORE_ADDR base = (CORE_ADDR) 0;
22 @@ -7695,20 +7697,67 @@ read_common_block (struct die_info *die,
24 if (die->child != NULL)
26 + struct objfile *objfile = cu->objfile;
27 + struct die_info *child_die;
29 + struct field *field;
33 + type = alloc_type (objfile);
34 + TYPE_CODE (type) = TYPE_CODE_STRUCT;
35 + /* Artificial type to be used only by `info common'. */
36 + TYPE_NAME (type) = "<common>";
38 + child_die = die->child;
39 + while (child_die && child_die->tag)
41 + TYPE_NFIELDS (type)++;
42 + child_die = sibling_die (child_die);
45 + TYPE_FIELDS (type) = obstack_alloc (&objfile->objfile_obstack,
46 + sizeof (*TYPE_FIELDS (type))
47 + * TYPE_NFIELDS (type));
48 + memset (TYPE_FIELDS (type), 0, sizeof (*TYPE_FIELDS (type))
49 + * TYPE_NFIELDS (type));
51 + field = TYPE_FIELDS (type);
52 child_die = die->child;
53 while (child_die && child_die->tag)
57 + /* Create the symbol in the DW_TAG_common_block block in the current
59 sym = new_symbol (child_die, NULL, cu);
61 + /* Undocumented in DWARF3, when it can be present? */
63 && handle_data_member_location (child_die, cu, &offset))
65 SYMBOL_VALUE_ADDRESS (sym) = base + offset;
66 add_symbol_to_list (sym, &global_symbols);
69 + if (SYMBOL_CLASS (sym) == LOC_STATIC)
70 + SET_FIELD_PHYSADDR (*field, SYMBOL_VALUE_ADDRESS (sym));
72 + SET_FIELD_PHYSNAME (*field, SYMBOL_LINKAGE_NAME (sym));
73 + FIELD_TYPE (*field) = SYMBOL_TYPE (sym);
74 + FIELD_NAME (*field) = SYMBOL_NATURAL_NAME (sym);
76 child_die = sibling_die (child_die);
79 + /* TYPE_LENGTH (type) is left 0 - it is only a virtual structure even
80 + with no consecutive address space. */
82 + sym = new_symbol (die, type, cu);
83 + /* SYMBOL_VALUE_ADDRESS never gets used as all its fields are static. */
84 + SYMBOL_VALUE_ADDRESS (sym) = base;
86 + set_die_type (die, type, cu);
90 @@ -11376,6 +11425,13 @@ new_symbol_full (struct die_info *die, s
92 var_decode_location (attr, sym, cu);
93 attr2 = dwarf2_attr (die, DW_AT_external, cu);
95 + /* Fortran explicitly imports any global symbols to the local
96 + scope by DW_TAG_common_block. */
97 + if (cu->language == language_fortran && die->parent
98 + && die->parent->tag == DW_TAG_common_block)
101 if (SYMBOL_CLASS (sym) == LOC_STATIC
102 && SYMBOL_VALUE_ADDRESS (sym) == 0
103 && !dwarf2_per_objfile->has_section_at_zero)
104 @@ -11548,6 +11604,11 @@ new_symbol_full (struct die_info *die, s
105 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
106 list_to_add = &global_symbols;
108 + case DW_TAG_common_block:
109 + SYMBOL_CLASS (sym) = LOC_STATIC;
110 + SYMBOL_DOMAIN (sym) = COMMON_BLOCK_DOMAIN;
111 + add_symbol_to_list (sym, cu->list_in_scope);
114 /* Not a tag we recognize. Hopefully we aren't processing
115 trash data, but since we must specifically ignore things
116 Index: gdb-7.2.90.20110525/gdb/f-lang.c
117 ===================================================================
118 --- gdb-7.2.90.20110525.orig/gdb/f-lang.c 2011-05-25 17:06:22.000000000 +0200
119 +++ gdb-7.2.90.20110525/gdb/f-lang.c 2011-05-25 17:07:02.000000000 +0200
120 @@ -446,27 +446,3 @@ _initialize_f_language (void)
122 add_language (&f_language_defn);
125 -SAVED_F77_COMMON_PTR head_common_list = NULL; /* Ptr to 1st saved COMMON */
127 -/* This routine finds the first encountred COMMON block named "name"
128 - that belongs to function funcname. */
130 -SAVED_F77_COMMON_PTR
131 -find_common_for_function (char *name, char *funcname)
134 - SAVED_F77_COMMON_PTR tmp;
136 - tmp = head_common_list;
138 - while (tmp != NULL)
140 - if (strcmp (tmp->name, name) == 0
141 - && strcmp (tmp->owning_function, funcname) == 0)
148 Index: gdb-7.2.90.20110525/gdb/f-lang.h
149 ===================================================================
150 --- gdb-7.2.90.20110525.orig/gdb/f-lang.h 2011-05-25 17:06:22.000000000 +0200
151 +++ gdb-7.2.90.20110525/gdb/f-lang.h 2011-05-25 17:07:02.000000000 +0200
152 @@ -52,36 +52,8 @@ enum f90_range_type
153 NONE_BOUND_DEFAULT /* "(low:high)" */
158 - struct symbol *symbol; /* The symbol node corresponding
159 - to this component */
160 - struct common_entry *next; /* The next component */
163 -struct saved_f77_common
165 - char *name; /* Name of COMMON */
166 - char *owning_function; /* Name of parent function */
167 - int secnum; /* Section # of .bss */
168 - CORE_ADDR offset; /* Offset from .bss for
170 - struct common_entry *entries; /* List of block's components */
171 - struct common_entry *end_of_entries; /* ptr. to end of components */
172 - struct saved_f77_common *next; /* Next saved COMMON block */
175 -typedef struct saved_f77_common SAVED_F77_COMMON, *SAVED_F77_COMMON_PTR;
177 -typedef struct common_entry COMMON_ENTRY, *COMMON_ENTRY_PTR;
179 -extern SAVED_F77_COMMON_PTR head_common_list; /* Ptr to 1st saved COMMON */
181 -extern SAVED_F77_COMMON_PTR find_common_for_function (char *, char *);
183 #define BLANK_COMMON_NAME_ORIGINAL "#BLNK_COM" /* XLF assigned */
184 #define BLANK_COMMON_NAME_MF77 "__BLNK__" /* MF77 assigned */
185 -#define BLANK_COMMON_NAME_LOCAL "__BLANK" /* Local GDB */
187 /* When reasonable array bounds cannot be fetched, such as when
188 you ask to 'mt print symbols' and there is no stack frame and
189 Index: gdb-7.2.90.20110525/gdb/f-valprint.c
190 ===================================================================
191 --- gdb-7.2.90.20110525.orig/gdb/f-valprint.c 2011-05-25 17:06:22.000000000 +0200
192 +++ gdb-7.2.90.20110525/gdb/f-valprint.c 2011-05-25 17:07:02.000000000 +0200
197 +#include "dictionary.h"
198 +#include "gdb_assert.h"
200 extern void _initialize_f_valprint (void);
201 static void info_common_command (char *, int);
202 @@ -501,22 +503,54 @@ f_val_print (struct type *type, const gd
207 -list_all_visible_commons (char *funname)
209 +info_common_command_for_block (struct block *block, struct frame_info *frame,
210 + const char *comname)
212 - SAVED_F77_COMMON_PTR tmp;
214 - tmp = head_common_list;
215 + struct dict_iterator iter;
216 + struct symbol *sym;
217 + int values_printed = 0;
219 + struct value_print_options opts;
221 + get_user_print_options (&opts);
223 + ALL_BLOCK_SYMBOLS (block, iter, sym)
224 + if (SYMBOL_DOMAIN (sym) == COMMON_BLOCK_DOMAIN)
226 + struct type *type = SYMBOL_TYPE (sym);
229 + gdb_assert (SYMBOL_CLASS (sym) == LOC_STATIC);
230 + gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT);
232 + if (comname && (!SYMBOL_LINKAGE_NAME (sym)
233 + || strcmp (comname, SYMBOL_LINKAGE_NAME (sym)) != 0))
236 + values_printed = 1;
237 + if (SYMBOL_PRINT_NAME (sym))
238 + printf_filtered (_("Contents of F77 COMMON block '%s':\n"),
239 + SYMBOL_PRINT_NAME (sym));
241 + printf_filtered (_("Contents of blank COMMON block:\n"));
243 + for (index = 0; index < TYPE_NFIELDS (type); index++)
247 + gdb_assert (field_is_static (&TYPE_FIELD (type, index)));
248 + val = value_static_field (type, index);
250 + printf_filtered ("%s = ", TYPE_FIELD_NAME (type, index));
251 + value_print (val, gdb_stdout, &opts);
252 + putchar_filtered ('\n');
255 - printf_filtered (_("All COMMON blocks visible at this level:\n\n"));
256 + putchar_filtered ('\n');
259 - while (tmp != NULL)
261 - if (strcmp (tmp->owning_function, funname) == 0)
262 - printf_filtered ("%s\n", tmp->name);
266 + return values_printed;
269 /* This function is used to print out the values in a given COMMON
270 @@ -526,11 +560,9 @@ list_all_visible_commons (char *funname)
272 info_common_command (char *comname, int from_tty)
274 - SAVED_F77_COMMON_PTR the_common;
275 - COMMON_ENTRY_PTR entry;
276 struct frame_info *fi;
278 - struct symbol *func;
279 + struct block *block;
280 + int values_printed = 0;
282 /* We have been told to display the contents of F77 COMMON
283 block supposedly visible in this function. Let us
284 @@ -542,74 +574,31 @@ info_common_command (char *comname, int
285 /* The following is generally ripped off from stack.c's routine
286 print_frame_info(). */
288 - func = find_pc_function (get_frame_pc (fi));
290 + block = get_frame_block (fi, 0);
293 - /* In certain pathological cases, the symtabs give the wrong
294 - function (when we are in the first function in a file which
295 - is compiled without debugging symbols, the previous function
296 - is compiled with debugging symbols, and the "foo.o" symbol
297 - that is supposed to tell us where the file with debugging symbols
298 - ends has been truncated by ar because it is longer than 15
301 - So look in the minimal symbol tables as well, and if it comes
302 - up with a larger address for the function use that instead.
303 - I don't think this can ever cause any problems; there shouldn't
304 - be any minimal symbols in the middle of a function.
305 - FIXME: (Not necessarily true. What about text labels?) */
307 - struct minimal_symbol *msymbol =
308 - lookup_minimal_symbol_by_pc (get_frame_pc (fi));
310 - if (msymbol != NULL
311 - && (SYMBOL_VALUE_ADDRESS (msymbol)
312 - > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
313 - funname = SYMBOL_LINKAGE_NAME (msymbol);
315 - funname = SYMBOL_LINKAGE_NAME (func);
319 - struct minimal_symbol *msymbol =
320 - lookup_minimal_symbol_by_pc (get_frame_pc (fi));
322 - if (msymbol != NULL)
323 - funname = SYMBOL_LINKAGE_NAME (msymbol);
324 - else /* Got no 'funname', code below will fail. */
325 - error (_("No function found for frame."));
326 + printf_filtered (_("No symbol table info available.\n"));
330 - /* If comname is NULL, we assume the user wishes to see the
331 - which COMMON blocks are visible here and then return. */
336 - list_all_visible_commons (funname);
338 + if (info_common_command_for_block (block, fi, comname))
339 + values_printed = 1;
340 + /* After handling the function's top-level block, stop. Don't
341 + continue to its superblock, the block of per-file symbols. */
342 + if (BLOCK_FUNCTION (block))
344 + block = BLOCK_SUPERBLOCK (block);
347 - the_common = find_common_for_function (comname, funname);
350 + if (!values_printed)
352 - if (strcmp (comname, BLANK_COMMON_NAME_LOCAL) == 0)
353 - printf_filtered (_("Contents of blank COMMON block:\n"));
355 + printf_filtered (_("No common block '%s'.\n"), comname);
357 - printf_filtered (_("Contents of F77 COMMON block '%s':\n"), comname);
359 - printf_filtered ("\n");
360 - entry = the_common->entries;
362 - while (entry != NULL)
364 - print_variable_and_value (NULL, entry->symbol, fi, gdb_stdout, 0);
365 - entry = entry->next;
367 + printf_filtered (_("No common blocks.\n"));
370 - printf_filtered (_("Cannot locate the common block %s in function '%s'\n"),
375 Index: gdb-7.2.90.20110525/gdb/stack.c
376 ===================================================================
377 --- gdb-7.2.90.20110525.orig/gdb/stack.c 2011-05-25 17:05:21.000000000 +0200
378 +++ gdb-7.2.90.20110525/gdb/stack.c 2011-05-25 17:07:02.000000000 +0200
379 @@ -1525,6 +1525,8 @@ iterate_over_block_locals (struct block
381 if (SYMBOL_IS_ARGUMENT (sym))
383 + if (SYMBOL_DOMAIN (sym) == COMMON_BLOCK_DOMAIN)
385 (*cb) (SYMBOL_PRINT_NAME (sym), sym, cb_data);
388 Index: gdb-7.2.90.20110525/gdb/symtab.h
389 ===================================================================
390 --- gdb-7.2.90.20110525.orig/gdb/symtab.h 2011-05-25 17:05:21.000000000 +0200
391 +++ gdb-7.2.90.20110525/gdb/symtab.h 2011-05-25 17:07:02.000000000 +0200
392 @@ -411,7 +411,10 @@ typedef enum domain_enum_tag
399 + /* Fortran common blocks. Their naming must be separate from VAR_DOMAIN. */
400 + COMMON_BLOCK_DOMAIN
404 Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.fortran/common-block.exp
405 ===================================================================
406 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
407 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.fortran/common-block.exp 2011-05-25 17:07:02.000000000 +0200
409 +# Copyright 2008 Free Software Foundation, Inc.
411 +# This program is free software; you can redistribute it and/or modify
412 +# it under the terms of the GNU General Public License as published by
413 +# the Free Software Foundation; either version 2 of the License, or
414 +# (at your option) any later version.
416 +# This program is distributed in the hope that it will be useful,
417 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
418 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
419 +# GNU General Public License for more details.
421 +# You should have received a copy of the GNU General Public License
422 +# along with this program; if not, write to the Free Software
423 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
425 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
427 +set testfile "common-block"
428 +set srcfile ${testfile}.f90
429 +set binfile ${objdir}/${subdir}/${testfile}
431 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f77 quiet}] != "" } {
432 + untested "Couldn't compile ${srcfile}"
438 +gdb_reinitialize_dir $srcdir/$subdir
441 +if ![runto MAIN__] then {
442 + perror "couldn't run to breakpoint MAIN__"
446 +gdb_breakpoint [gdb_get_line_number "stop-here-out"]
447 +gdb_continue_to_breakpoint "stop-here-out"
449 +# Common block naming with source name /foo/:
450 +# .symtab DW_TAG_common_block's DW_AT_name
451 +# Intel Fortran foo_ foo_
452 +# GNU Fortran foo_ foo
456 +set int4 {(integer\(kind=4\)|INTEGER\(4\))}
457 +set real4 {(real\(kind=4\)|REAL\(4\))}
458 +set real8 {(real\(kind=8\)|REAL\(8\))}
460 +gdb_test "whatis foo$suffix" "No symbol \"foo$suffix\" in current context."
461 +gdb_test "ptype foo$suffix" "No symbol \"foo$suffix\" in current context."
462 +gdb_test "p foo$suffix" "No symbol \"foo$suffix\" in current context."
463 +gdb_test "whatis fo_o$suffix" "No symbol \"fo_o$suffix\" in current context."
464 +gdb_test "ptype fo_o$suffix" "No symbol \"fo_o$suffix\" in current context."
465 +gdb_test "p fo_o$suffix" "No symbol \"fo_o$suffix\" in current context."
467 +gdb_test "info locals" "ix_x = 11\r\niy_y = 22\r\niz_z = 33\r\nix = 1\r\niy = 2\r\niz = 3" "info locals out"
468 +gdb_test "info common" "Contents of F77 COMMON block 'fo_o':\r\nix_x = 11\r\niy_y = 22\r\niz_z = 33\r\n\r\nContents of F77 COMMON block 'foo':\r\nix = 1\r\niy = 2\r\niz = 3" "info common out"
470 +gdb_test "ptype ix" "type = $int4" "ptype ix out"
471 +gdb_test "ptype iy" "type = $real4" "ptype iy out"
472 +gdb_test "ptype iz" "type = $real8" "ptype iz out"
473 +gdb_test "ptype ix_x" "type = $int4" "ptype ix_x out"
474 +gdb_test "ptype iy_y" "type = $real4" "ptype iy_y out"
475 +gdb_test "ptype iz_z" "type = $real8" "ptype iz_z out"
477 +gdb_test "p ix" " = 1 *" "p ix out"
478 +gdb_test "p iy" " = 2 *" "p iy out"
479 +gdb_test "p iz" " = 3 *" "p iz out"
480 +gdb_test "p ix_x" " = 11 *" "p ix_x out"
481 +gdb_test "p iy_y" " = 22 *" "p iy_y out"
482 +gdb_test "p iz_z" " = 33 *" "p iz_z out"
484 +gdb_breakpoint [gdb_get_line_number "stop-here-in"]
485 +gdb_continue_to_breakpoint "stop-here-in"
487 +gdb_test "whatis foo$suffix" "No symbol \"foo$suffix\" in current context." "whatis foo$suffix in"
488 +gdb_test "ptype foo$suffix" "No symbol \"foo$suffix\" in current context." "ptype foo$suffix in"
489 +gdb_test "p foo$suffix" "No symbol \"foo$suffix\" in current context." "p foo$suffix in"
490 +gdb_test "whatis fo_o$suffix" "No symbol \"fo_o$suffix\" in current context." "whatis fo_o$suffix in"
491 +gdb_test "ptype fo_o$suffix" "No symbol \"fo_o$suffix\" in current context." "ptype fo_o$suffix in"
492 +gdb_test "p fo_o$suffix" "No symbol \"fo_o$suffix\" in current context." "p fo_o$suffix in"
494 +gdb_test "info locals" "ix = 11\r\niy2 = 22\r\niz = 33\r\nix_x = 1\r\niy_y = 2\r\niz_z2 = 3\r\niy = 5\r\niz_z = 55" "info locals in"
495 +gdb_test "info common" "Contents of F77 COMMON block 'fo_o':\r\nix = 11\r\niy2 = 22\r\niz = 33\r\n\r\nContents of F77 COMMON block 'foo':\r\nix_x = 1\r\niy_y = 2\r\niz_z2 = 3" "info common in"
497 +gdb_test "ptype ix" "type = $int4" "ptype ix in"
498 +gdb_test "ptype iy2" "type = $real4" "ptype iy2 in"
499 +gdb_test "ptype iz" "type = $real8" "ptype iz in"
500 +gdb_test "ptype ix_x" "type = $int4" "ptype ix_x in"
501 +gdb_test "ptype iy_y" "type = $real4" "ptype iy_y in"
502 +gdb_test "ptype iz_z2" "type = $real8" "ptype iz_z2 in"
504 +gdb_test "p ix" " = 11 *" "p ix in"
505 +gdb_test "p iy2" " = 22 *" "p iy2 in"
506 +gdb_test "p iz" " = 33 *" "p iz in"
507 +gdb_test "p ix_x" " = 1 *" "p ix_x in"
508 +gdb_test "p iy_y" " = 2 *" "p iy_y in"
509 +gdb_test "p iz_z2" " = 3 *" "p iz_z2 in"
510 Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.fortran/common-block.f90
511 ===================================================================
512 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
513 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.fortran/common-block.f90 2011-05-25 17:07:02.000000000 +0200
515 +! Copyright 2008 Free Software Foundation, Inc.
517 +! This program is free software; you can redistribute it and/or modify
518 +! it under the terms of the GNU General Public License as published by
519 +! the Free Software Foundation; either version 2 of the License, or
520 +! (at your option) any later version.
522 +! This program is distributed in the hope that it will be useful,
523 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
524 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
525 +! GNU General Public License for more details.
527 +! You should have received a copy of the GNU General Public License
528 +! along with this program; if not, write to the Free Software
529 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
531 +! Ihis file is the Fortran source file for dynamic.exp.
532 +! Original file written by Jakub Jelinek <jakub@redhat.com>.
533 +! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
545 + common /fo_o/ix,iy2,iz
546 + common /foo/ix_x,iy_y,iz_z2
551 + if (ix .ne. 11 .or. iy2 .ne. 22.0 .or. iz .ne. 33.0) call abort
552 + if (ix_x .ne. 1 .or. iy_y .ne. 2.0 .or. iz_z2 .ne. 3.0) call abort
554 + ix = 0 ! stop-here-in
568 + common /foo/ix,iy,iz
569 + common /fo_o/ix_x,iy_y,iz_z
579 + call in ! stop-here-out
581 +end program common_test