1 Index: gdb-7.1.90.20100711/gdb/dwarf2read.c
2 ===================================================================
3 --- gdb-7.1.90.20100711.orig/gdb/dwarf2read.c 2010-07-13 00:13:02.000000000 +0200
4 +++ gdb-7.1.90.20100711/gdb/dwarf2read.c 2010-07-13 00:26:25.000000000 +0200
5 @@ -5727,12 +5727,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 @@ -5757,10 +5759,40 @@ 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)
55 + /* Create the symbol in the DW_TAG_common_block block in the current
57 sym = new_symbol (child_die, NULL, cu);
59 + /* Undocumented in DWARF3, when it can be present? */
60 attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu);
63 @@ -5778,8 +5810,25 @@ read_common_block (struct die_info *die,
64 SYMBOL_VALUE_ADDRESS (sym) = base + byte_offset;
65 add_symbol_to_list (sym, &global_symbols);
68 + if (SYMBOL_CLASS (sym) == LOC_STATIC)
69 + SET_FIELD_PHYSADDR (*field, SYMBOL_VALUE_ADDRESS (sym));
71 + SET_FIELD_PHYSNAME (*field, SYMBOL_LINKAGE_NAME (sym));
72 + FIELD_TYPE (*field) = SYMBOL_TYPE (sym);
73 + FIELD_NAME (*field) = SYMBOL_NATURAL_NAME (sym);
75 child_die = sibling_die (child_die);
78 + /* TYPE_LENGTH (type) is left 0 - it is only a virtual structure even
79 + with no consecutive address space. */
81 + sym = new_symbol (die, type, cu);
82 + /* SYMBOL_VALUE_ADDRESS never gets used as all its fields are static. */
83 + SYMBOL_VALUE_ADDRESS (sym) = base;
85 + set_die_type (die, type, cu);
89 @@ -9106,6 +9155,13 @@ new_symbol (struct die_info *die, struct
91 var_decode_location (attr, sym, cu);
92 attr2 = dwarf2_attr (die, DW_AT_external, cu);
94 + /* Fortran explicitly imports any global symbols to the local
95 + scope by DW_TAG_common_block. */
96 + if (cu->language == language_fortran && die->parent
97 + && die->parent->tag == DW_TAG_common_block)
100 if (attr2 && (DW_UNSND (attr2) != 0))
102 struct pending **list_to_add;
103 @@ -9277,6 +9333,11 @@ new_symbol (struct die_info *die, struct
104 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
105 add_symbol_to_list (sym, &global_symbols);
107 + case DW_TAG_common_block:
108 + SYMBOL_CLASS (sym) = LOC_STATIC;
109 + SYMBOL_DOMAIN (sym) = COMMON_BLOCK_DOMAIN;
110 + add_symbol_to_list (sym, cu->list_in_scope);
113 /* Not a tag we recognize. Hopefully we aren't processing
114 trash data, but since we must specifically ignore things
115 Index: gdb-7.1.90.20100711/gdb/f-lang.c
116 ===================================================================
117 --- gdb-7.1.90.20100711.orig/gdb/f-lang.c 2010-07-13 00:24:04.000000000 +0200
118 +++ gdb-7.1.90.20100711/gdb/f-lang.c 2010-07-13 00:25:56.000000000 +0200
119 @@ -443,27 +443,3 @@ _initialize_f_language (void)
121 add_language (&f_language_defn);
124 -SAVED_F77_COMMON_PTR head_common_list = NULL; /* Ptr to 1st saved COMMON */
126 -/* This routine finds the first encountred COMMON block named "name"
127 - that belongs to function funcname */
129 -SAVED_F77_COMMON_PTR
130 -find_common_for_function (char *name, char *funcname)
133 - SAVED_F77_COMMON_PTR tmp;
135 - tmp = head_common_list;
137 - while (tmp != NULL)
139 - if (strcmp (tmp->name, name) == 0
140 - && strcmp (tmp->owning_function, funcname) == 0)
147 Index: gdb-7.1.90.20100711/gdb/f-lang.h
148 ===================================================================
149 --- gdb-7.1.90.20100711.orig/gdb/f-lang.h 2010-07-13 00:24:04.000000000 +0200
150 +++ gdb-7.1.90.20100711/gdb/f-lang.h 2010-07-13 00:25:56.000000000 +0200
151 @@ -52,36 +52,8 @@ enum f90_range_type
152 NONE_BOUND_DEFAULT /* "(low:high)" */
157 - struct symbol *symbol; /* The symbol node corresponding
158 - to this component */
159 - struct common_entry *next; /* The next component */
162 -struct saved_f77_common
164 - char *name; /* Name of COMMON */
165 - char *owning_function; /* Name of parent function */
166 - int secnum; /* Section # of .bss */
167 - CORE_ADDR offset; /* Offset from .bss for
169 - struct common_entry *entries; /* List of block's components */
170 - struct common_entry *end_of_entries; /* ptr. to end of components */
171 - struct saved_f77_common *next; /* Next saved COMMON block */
174 -typedef struct saved_f77_common SAVED_F77_COMMON, *SAVED_F77_COMMON_PTR;
176 -typedef struct common_entry COMMON_ENTRY, *COMMON_ENTRY_PTR;
178 -extern SAVED_F77_COMMON_PTR head_common_list; /* Ptr to 1st saved COMMON */
180 -extern SAVED_F77_COMMON_PTR find_common_for_function (char *, char *);
182 #define BLANK_COMMON_NAME_ORIGINAL "#BLNK_COM" /* XLF assigned */
183 #define BLANK_COMMON_NAME_MF77 "__BLNK__" /* MF77 assigned */
184 -#define BLANK_COMMON_NAME_LOCAL "__BLANK" /* Local GDB */
186 /* When reasonable array bounds cannot be fetched, such as when
187 you ask to 'mt print symbols' and there is no stack frame and
188 Index: gdb-7.1.90.20100711/gdb/f-valprint.c
189 ===================================================================
190 --- gdb-7.1.90.20100711.orig/gdb/f-valprint.c 2010-07-13 00:24:25.000000000 +0200
191 +++ gdb-7.1.90.20100711/gdb/f-valprint.c 2010-07-13 00:32:05.000000000 +0200
196 +#include "dictionary.h"
197 +#include "gdb_assert.h"
199 extern void _initialize_f_valprint (void);
200 static void info_common_command (char *, int);
201 @@ -486,22 +488,54 @@ f_val_print (struct type *type, const gd
206 -list_all_visible_commons (char *funname)
208 +info_common_command_for_block (struct block *block, struct frame_info *frame,
209 + const char *comname)
211 - SAVED_F77_COMMON_PTR tmp;
213 - tmp = head_common_list;
214 + struct dict_iterator iter;
215 + struct symbol *sym;
216 + int values_printed = 0;
218 + struct value_print_options opts;
220 + get_user_print_options (&opts);
222 + ALL_BLOCK_SYMBOLS (block, iter, sym)
223 + if (SYMBOL_DOMAIN (sym) == COMMON_BLOCK_DOMAIN)
225 + struct type *type = SYMBOL_TYPE (sym);
228 + gdb_assert (SYMBOL_CLASS (sym) == LOC_STATIC);
229 + gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT);
231 + if (comname && (!SYMBOL_LINKAGE_NAME (sym)
232 + || strcmp (comname, SYMBOL_LINKAGE_NAME (sym)) != 0))
235 + values_printed = 1;
236 + if (SYMBOL_PRINT_NAME (sym))
237 + printf_filtered (_("Contents of F77 COMMON block '%s':\n"),
238 + SYMBOL_PRINT_NAME (sym));
240 + printf_filtered (_("Contents of blank COMMON block:\n"));
242 + for (index = 0; index < TYPE_NFIELDS (type); index++)
246 + gdb_assert (field_is_static (&TYPE_FIELD (type, index)));
247 + val = value_static_field (type, index);
249 + printf_filtered ("%s = ", TYPE_FIELD_NAME (type, index));
250 + value_print (val, gdb_stdout, &opts);
251 + putchar_filtered ('\n');
254 - printf_filtered (_("All COMMON blocks visible at this level:\n\n"));
255 + putchar_filtered ('\n');
258 - while (tmp != NULL)
260 - if (strcmp (tmp->owning_function, funname) == 0)
261 - printf_filtered ("%s\n", tmp->name);
265 + return values_printed;
268 /* This function is used to print out the values in a given COMMON
269 @@ -511,11 +545,9 @@ list_all_visible_commons (char *funname)
271 info_common_command (char *comname, int from_tty)
273 - SAVED_F77_COMMON_PTR the_common;
274 - COMMON_ENTRY_PTR entry;
275 struct frame_info *fi;
277 - struct symbol *func;
278 + struct block *block;
279 + int values_printed = 0;
281 /* We have been told to display the contents of F77 COMMON
282 block supposedly visible in this function. Let us
283 @@ -527,74 +559,31 @@ info_common_command (char *comname, int
284 /* The following is generally ripped off from stack.c's routine
285 print_frame_info() */
287 - func = find_pc_function (get_frame_pc (fi));
289 + block = get_frame_block (fi, 0);
292 - /* In certain pathological cases, the symtabs give the wrong
293 - function (when we are in the first function in a file which
294 - is compiled without debugging symbols, the previous function
295 - is compiled with debugging symbols, and the "foo.o" symbol
296 - that is supposed to tell us where the file with debugging symbols
297 - ends has been truncated by ar because it is longer than 15
300 - So look in the minimal symbol tables as well, and if it comes
301 - up with a larger address for the function use that instead.
302 - I don't think this can ever cause any problems; there shouldn't
303 - be any minimal symbols in the middle of a function.
304 - FIXME: (Not necessarily true. What about text labels) */
306 - struct minimal_symbol *msymbol =
307 - lookup_minimal_symbol_by_pc (get_frame_pc (fi));
309 - if (msymbol != NULL
310 - && (SYMBOL_VALUE_ADDRESS (msymbol)
311 - > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
312 - funname = SYMBOL_LINKAGE_NAME (msymbol);
314 - funname = SYMBOL_LINKAGE_NAME (func);
318 - struct minimal_symbol *msymbol =
319 - lookup_minimal_symbol_by_pc (get_frame_pc (fi));
321 - if (msymbol != NULL)
322 - funname = SYMBOL_LINKAGE_NAME (msymbol);
323 - else /* Got no 'funname', code below will fail. */
324 - error (_("No function found for frame."));
325 + printf_filtered (_("No symbol table info available.\n"));
329 - /* If comname is NULL, we assume the user wishes to see the
330 - which COMMON blocks are visible here and then return */
335 - list_all_visible_commons (funname);
337 + if (info_common_command_for_block (block, fi, comname))
338 + values_printed = 1;
339 + /* After handling the function's top-level block, stop. Don't
340 + continue to its superblock, the block of per-file symbols. */
341 + if (BLOCK_FUNCTION (block))
343 + block = BLOCK_SUPERBLOCK (block);
346 - the_common = find_common_for_function (comname, funname);
349 + if (!values_printed)
351 - if (strcmp (comname, BLANK_COMMON_NAME_LOCAL) == 0)
352 - printf_filtered (_("Contents of blank COMMON block:\n"));
354 + printf_filtered (_("No common block '%s'.\n"), comname);
356 - printf_filtered (_("Contents of F77 COMMON block '%s':\n"), comname);
358 - printf_filtered ("\n");
359 - entry = the_common->entries;
361 - while (entry != NULL)
363 - print_variable_and_value (NULL, entry->symbol, fi, gdb_stdout, 0);
364 - entry = entry->next;
366 + printf_filtered (_("No common blocks.\n"));
369 - printf_filtered (_("Cannot locate the common block %s in function '%s'\n"),
374 Index: gdb-7.1.90.20100711/gdb/stack.c
375 ===================================================================
376 --- gdb-7.1.90.20100711.orig/gdb/stack.c 2010-07-01 17:36:17.000000000 +0200
377 +++ gdb-7.1.90.20100711/gdb/stack.c 2010-07-13 00:29:49.000000000 +0200
378 @@ -1484,6 +1484,8 @@ iterate_over_block_locals (struct block
380 if (SYMBOL_IS_ARGUMENT (sym))
382 + if (SYMBOL_DOMAIN (sym) == COMMON_BLOCK_DOMAIN)
384 (*cb) (SYMBOL_PRINT_NAME (sym), sym, cb_data);
387 Index: gdb-7.1.90.20100711/gdb/symtab.h
388 ===================================================================
389 --- gdb-7.1.90.20100711.orig/gdb/symtab.h 2010-07-12 23:07:33.000000000 +0200
390 +++ gdb-7.1.90.20100711/gdb/symtab.h 2010-07-13 00:27:02.000000000 +0200
391 @@ -396,7 +396,10 @@ typedef enum domain_enum_tag
394 /* All defined types */
398 + /* Fortran common blocks. Their naming must be separate from VAR_DOMAIN. */
399 + COMMON_BLOCK_DOMAIN
403 Index: gdb-7.1.90.20100711/gdb/testsuite/gdb.fortran/common-block.exp
404 ===================================================================
405 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
406 +++ gdb-7.1.90.20100711/gdb/testsuite/gdb.fortran/common-block.exp 2010-07-13 00:25:56.000000000 +0200
408 +# Copyright 2008 Free Software Foundation, Inc.
410 +# This program is free software; you can redistribute it and/or modify
411 +# it under the terms of the GNU General Public License as published by
412 +# the Free Software Foundation; either version 2 of the License, or
413 +# (at your option) any later version.
415 +# This program is distributed in the hope that it will be useful,
416 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
417 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
418 +# GNU General Public License for more details.
420 +# You should have received a copy of the GNU General Public License
421 +# along with this program; if not, write to the Free Software
422 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
424 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
426 +set testfile "common-block"
427 +set srcfile ${testfile}.f90
428 +set binfile ${objdir}/${subdir}/${testfile}
430 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f77 quiet}] != "" } {
431 + untested "Couldn't compile ${srcfile}"
437 +gdb_reinitialize_dir $srcdir/$subdir
440 +if ![runto MAIN__] then {
441 + perror "couldn't run to breakpoint MAIN__"
445 +gdb_breakpoint [gdb_get_line_number "stop-here-out"]
446 +gdb_continue_to_breakpoint "stop-here-out"
448 +# Common block naming with source name /foo/:
449 +# .symtab DW_TAG_common_block's DW_AT_name
450 +# Intel Fortran foo_ foo_
451 +# GNU Fortran foo_ foo
455 +set int4 {(integer\(kind=4\)|INTEGER\(4\))}
456 +set real4 {(real\(kind=4\)|REAL\(4\))}
457 +set real8 {(real\(kind=8\)|REAL\(8\))}
459 +gdb_test "whatis foo$suffix" "No symbol \"foo$suffix\" in current context."
460 +gdb_test "ptype foo$suffix" "No symbol \"foo$suffix\" in current context."
461 +gdb_test "p foo$suffix" "No symbol \"foo$suffix\" in current context."
462 +gdb_test "whatis fo_o$suffix" "No symbol \"fo_o$suffix\" in current context."
463 +gdb_test "ptype fo_o$suffix" "No symbol \"fo_o$suffix\" in current context."
464 +gdb_test "p fo_o$suffix" "No symbol \"fo_o$suffix\" in current context."
466 +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"
467 +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"
469 +gdb_test "ptype ix" "type = $int4" "ptype ix out"
470 +gdb_test "ptype iy" "type = $real4" "ptype iy out"
471 +gdb_test "ptype iz" "type = $real8" "ptype iz out"
472 +gdb_test "ptype ix_x" "type = $int4" "ptype ix_x out"
473 +gdb_test "ptype iy_y" "type = $real4" "ptype iy_y out"
474 +gdb_test "ptype iz_z" "type = $real8" "ptype iz_z out"
476 +gdb_test "p ix" " = 1 *" "p ix out"
477 +gdb_test "p iy" " = 2 *" "p iy out"
478 +gdb_test "p iz" " = 3 *" "p iz out"
479 +gdb_test "p ix_x" " = 11 *" "p ix_x out"
480 +gdb_test "p iy_y" " = 22 *" "p iy_y out"
481 +gdb_test "p iz_z" " = 33 *" "p iz_z out"
483 +gdb_breakpoint [gdb_get_line_number "stop-here-in"]
484 +gdb_continue_to_breakpoint "stop-here-in"
486 +gdb_test "whatis foo$suffix" "No symbol \"foo$suffix\" in current context." "whatis foo$suffix in"
487 +gdb_test "ptype foo$suffix" "No symbol \"foo$suffix\" in current context." "ptype foo$suffix in"
488 +gdb_test "p foo$suffix" "No symbol \"foo$suffix\" in current context." "p foo$suffix in"
489 +gdb_test "whatis fo_o$suffix" "No symbol \"fo_o$suffix\" in current context." "whatis fo_o$suffix in"
490 +gdb_test "ptype fo_o$suffix" "No symbol \"fo_o$suffix\" in current context." "ptype fo_o$suffix in"
491 +gdb_test "p fo_o$suffix" "No symbol \"fo_o$suffix\" in current context." "p fo_o$suffix in"
493 +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"
494 +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"
496 +gdb_test "ptype ix" "type = $int4" "ptype ix in"
497 +gdb_test "ptype iy2" "type = $real4" "ptype iy2 in"
498 +gdb_test "ptype iz" "type = $real8" "ptype iz in"
499 +gdb_test "ptype ix_x" "type = $int4" "ptype ix_x in"
500 +gdb_test "ptype iy_y" "type = $real4" "ptype iy_y in"
501 +gdb_test "ptype iz_z2" "type = $real8" "ptype iz_z2 in"
503 +gdb_test "p ix" " = 11 *" "p ix in"
504 +gdb_test "p iy2" " = 22 *" "p iy2 in"
505 +gdb_test "p iz" " = 33 *" "p iz in"
506 +gdb_test "p ix_x" " = 1 *" "p ix_x in"
507 +gdb_test "p iy_y" " = 2 *" "p iy_y in"
508 +gdb_test "p iz_z2" " = 3 *" "p iz_z2 in"
509 Index: gdb-7.1.90.20100711/gdb/testsuite/gdb.fortran/common-block.f90
510 ===================================================================
511 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
512 +++ gdb-7.1.90.20100711/gdb/testsuite/gdb.fortran/common-block.f90 2010-07-13 00:25:56.000000000 +0200
514 +! Copyright 2008 Free Software Foundation, Inc.
516 +! This program is free software; you can redistribute it and/or modify
517 +! it under the terms of the GNU General Public License as published by
518 +! the Free Software Foundation; either version 2 of the License, or
519 +! (at your option) any later version.
521 +! This program is distributed in the hope that it will be useful,
522 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
523 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
524 +! GNU General Public License for more details.
526 +! You should have received a copy of the GNU General Public License
527 +! along with this program; if not, write to the Free Software
528 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
530 +! Ihis file is the Fortran source file for dynamic.exp.
531 +! Original file written by Jakub Jelinek <jakub@redhat.com>.
532 +! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
544 + common /fo_o/ix,iy2,iz
545 + common /foo/ix_x,iy_y,iz_z2
550 + if (ix .ne. 11 .or. iy2 .ne. 22.0 .or. iz .ne. 33.0) call abort
551 + if (ix_x .ne. 1 .or. iy_y .ne. 2.0 .or. iz_z2 .ne. 3.0) call abort
553 + ix = 0 ! stop-here-in
567 + common /foo/ix,iy,iz
568 + common /fo_o/ix_x,iy_y,iz_z
578 + call in ! stop-here-out
580 +end program common_test