Re: [RFA/DWARF2] Handle nested subprograms in CU pc bound calculation

Joel Brobecker
2008-10-01T01:16:15Z

[-- Attachment #1: Type: text/plain, Size: 1657 bytes --]

> > Actually, now that I think of it, a slightly cleaner approach would
> > probably be to extend the language vector to add a flag set to non-zero
> > for the languages that want nested-subprogram handling. The only slight
> > issue is that the CU references the language enum, which means we need
> > to go from that enum to the language_defn to get access to the flag.
>
> I think you should stick with a language test in the DWARF reader.

OK. Would the following kind of patch be what you have in mind?
Or would you prefer that the function simply take a language,
rather than a CU. Or actually no function at all?

2008-09-30 Joel Brobecker <brobecker@adacore.com>

* dwarf2read.c (dwarf2_handle_nested_subprograms_p): New function.
(add_partial_subprogram): Replace check of Ada language by call
to dwarf2_handle_nested_subprograms_p.
(dwarf2_get_subprogram_pc_bounds, load_partial_dies): Likewise.

This is only just for comments, as there is still one question open:
For Ada, we store the symbols for nested subprograms in the global
context. This allows us to break on these functions even when these
functions are not defined in the current context. Do we want to do
the same with Pascal? Right now, I left this functionality out...
In Ada, we have found it to be extremely convenient to not have to
be inside the enclosing function before we can insert the breakpoint.
When there are ambiguities (say two functions have a nested subprogram
with the same name), the ambiguity can be resolved using the fully
qualified name.

Tested on x86-linux, no regression (but I don't have a Pascal compiler).

--
Joel

[-- Attachment #2: pascal-nested.diff --]
[-- Type: text/plain, Size: 1796 bytes --]

diff -r 5c068b86064f dwarf2read.c
--- a/dwarf2read.c Tue Sep 30 15:08:26 2008 -0700
+++ b/dwarf2read.c Tue Sep 30 18:09:41 2008 -0700
@@ -1217,6 +1217,19 @@ dwarf2_resize_section (asection *sectp,
sectp->name);
}

+/* Return non-zero if the given CU may contains some nested subprograms
+ (in other words, subprograms defined inside another subprogram or
+ inside a lexical block).
+
+ The result is currently purely based on the compilation unit language,
+ and thus the content of the compilation unit itself is not checked. */
+
+static int
+dwarf2_handle_nested_subprograms_p (struct dwarf2_cu *cu)
+{
+ return (cu->language == language_ada || cu->language == language_pascal);
+}
+
/* Build a partial symbol table. */

void
@@ -2163,7 +2176,7 @@ add_partial_subprogram (struct partial_d
if (! pdi->has_children)
return;

- if (cu->language == language_ada)
+ if (dwarf2_handle_nested_subprograms_p (cu))
{
pdi = pdi->die_child;
while (pdi != NULL)
@@ -3345,7 +3358,7 @@ dwarf2_get_subprogram_pc_bounds (struct

/* If the language does not allow nested subprograms (either inside
subprograms or lexical blocks), we're done. */
- if (cu->language != language_ada)
+ if (!dwarf2_handle_nested_subprograms_p (cu))
return;

/* Check all the children of the given DIE. If it contains nested
@@ -5770,7 +5783,7 @@ load_partial_dies (bfd *abfd, gdb_byte *
|| last_die->tag == DW_TAG_interface_type
|| last_die->tag == DW_TAG_structure_type
|| last_die->tag == DW_TAG_union_type))
- || (cu->language == language_ada
+ || (dwarf2_handle_nested_subprograms_p (cu)
&& (last_die->tag == DW_TAG_subprogram
|| last_die->tag == DW_TAG_lexical_block))))
{