This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 3/8] Code cleanup: Split dwarf2_ranges_read to a callback


On 02/12/2017 08:23 PM, Jan Kratochvil wrote:

> -/* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
> -   Return 1 if the attributes are present and valid, otherwise, return 0.
> -   If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'.  */
> +/* Call CALLBACK from DW_AT_ranges attribute value OFFSET.
> +   Return 1 if the attributes are present and valid, otherwise, return 0.  */
>  
>  static int
> -dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
> -		    CORE_ADDR *high_return, struct dwarf2_cu *cu,
> -		    struct partial_symtab *ranges_pst)
> +dwarf2_ranges_process (unsigned offset, struct dwarf2_cu *cu,
> +		       std::function<void (CORE_ADDR range_beginning,
> +					   CORE_ADDR range_end)> callback)

std::function is a lot of unnecessary overhead here.  Unless you
manage to trigger to small-function optimization (which you won't here,
the callbacks are too big), this is forcing a heap allocation inside
std::function for every call to dwarf2_ranges_process.

Let's only use std::function for it's intended use-case of when the
design calls for taking, or more usually, storing, a callable whose
type is not knowable at compile type.  In this case, the type is
determinable at compile type, as everything is local to the same file
and the callees are always known.

So make dwarf2_ranges_process a template, and the overhead disappears,
like:

~~~~~~~~~~~~~~~~~~
diff --git c/gdb/dwarf2read.c w/gdb/dwarf2read.c
index 1137541..94d5de2 100644
--- c/gdb/dwarf2read.c
+++ w/gdb/dwarf2read.c
@@ -11877,10 +11877,13 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET.
    Return 1 if the attributes are present and valid, otherwise, return 0.  */
 
+/* Callback's type should be:
+    void (CORE_ADDR range_beginning, CORE_ADDR range_end)
+*/
+template <typename Callback>
 static int
 dwarf2_ranges_process (unsigned offset, struct dwarf2_cu *cu,
-                      std::function<void (CORE_ADDR range_beginning,
-                                          CORE_ADDR range_end)> callback)
+                      Callback callback)
 {
~~~~~~~~~~~~~~~~~~

OK with that change.

Thanks,
Pedro Alves


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]