From 671c004cc4dcd29606641ea1caee663905a9dcff Mon Sep 17 00:00:00 2001 From: Bernhard Heckel Date: Thu, 30 Jun 2016 14:11:03 +0200 Subject: [PATCH] Fortran: Enable setting breakpoint on nested functions. Like in Ada, we want to be able to set a breakpoint on nested functions, called "contained routines" in Fortran. 2016-06-30 Bernhard Heckel gdb/Changelog: * dwarf2read.c (todo) gdb/Changelog: * gdb.fortran/nested-funcs.exp: Set breakpoint on contained routines. Change-Id: I7f2897f8f3160c0d5618850273d87579cc2479c8 --- gdb/dwarf2read.c | 9 +++++++-- gdb/testsuite/gdb.fortran/nested-funcs.exp | 8 ++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 945ca614ac1..cba551d444e 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -6936,7 +6936,9 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) break; case DW_TAG_subprogram: addr = gdbarch_adjust_dwarf2_addr (gdbarch, pdi->lowpc + baseaddr); - if (pdi->is_external || cu->language == language_ada) + if (pdi->is_external + || cu->language == language_ada + || cu->language == language_fortran) { /* brobecker/2007-12-26: Normally, only "external" DIEs are part of the global scope. But in Ada, we want to be able to access @@ -7219,6 +7221,8 @@ add_partial_subprogram (struct partial_die_info *pdi, { if (pdi->tag == DW_TAG_entry_point) add_partial_entry_point (pdi, lowpc, highpc, set_addrmap, cu); + else if (pdi->tag == DW_TAG_subprogram) + add_partial_subprogram (pdi, lowpc, highpc, set_addrmap, cu); pdi = pdi->die_sibling; } } @@ -18530,7 +18534,8 @@ new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu, SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK; attr2 = dwarf2_attr (die, DW_AT_external, cu); if ((attr2 && (DW_UNSND (attr2) != 0)) - || cu->language == language_ada) + || cu->language == language_ada + || cu->language == language_fortran) { /* Subprograms marked external are stored as a global symbol. Ada subprograms, whether marked external or not, are always diff --git a/gdb/testsuite/gdb.fortran/nested-funcs.exp b/gdb/testsuite/gdb.fortran/nested-funcs.exp index 976aa22a05b..d098ba197c9 100755 --- a/gdb/testsuite/gdb.fortran/nested-funcs.exp +++ b/gdb/testsuite/gdb.fortran/nested-funcs.exp @@ -30,6 +30,10 @@ if ![runto MAIN__] then { continue } +# Test if we can set a breakpoint in a nested function +gdb_breakpoint "sub_nested_outer" +gdb_continue_to_breakpoint "sub_nested_outer" ".*local_int = 19" + # Test if we can access local and # non-local variables defined one level up. gdb_breakpoint [gdb_get_line_number "! BP_outer"] @@ -43,6 +47,10 @@ gdb_test "print local_int" "= 19" "print local_int in outer function" gdb_test "up" gdb_test "print index" "= 42" "print index at BP1, one frame up" +# Test if we can set a breakpoint in a nested function +gdb_breakpoint "sub_nested_inner" +gdb_continue_to_breakpoint "sub_nested_inner" ".*local_int = 17" + # Test if we can access local and # non-local variables defined two level up. gdb_breakpoint [gdb_get_line_number "! BP_inner"]