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]

[PATCH 0/3] Introduce gdb::function_view & fix completion bug


I noticed that gdb.base/completion.exp fails when run with
--target_board=dwarf4-gdb-index.  In order to fix it, I wanted to use
a lambda with iterate_over_symtabs.  However, the C-style "function
pointer" + "data pointer" callback style we are still using doesn't
play well with lambdas with captures.

C++11 gave us std::function as type-erased wrapper around arbitrary
callables, however, as I explained at [1] in detail (with references),
std::function is not an ideal fit for transient callbacks.  A better
type for that is a non-owning version of std::function.  Using modern
C++17 terminology, the natural name for such an object is a "view",
thus "function_view".  There are several examples of such a thing in
the interwebs.  This series adds such a type to GDB.

This version is more complete than any other I've seen.  It supports
function pointers efficiently without hitting undefined behavior, it
supports comparison with NULL like std::function, and it supports
referencing callables that return non-void when the function_view is
expecting void, just like std::function too.  (Speaking of which, I've
looked at libstdc++'s std::function to compare APIs, and stolen a few
traits bits from there while at it).  Unit tests to cover the whole
API are included too.

[1] - https://sourceware.org/ml/gdb-patches/2017-02/msg00535.html

Regtested on x86_64 Fedora 23, and build tested with GCC 4.8.5 too.

Also pushed to the users/palves/function-view branch on sourceware.org.

Pedro Alves (3):
  Introduce gdb::function_view
  Use gdb::function_view in iterate_over_symtabs & co
  Fix gdb.base/completion.exp with --target_board=dwarf4-gdb-index

 gdb/Makefile.in                         |  24 ++-
 gdb/ada-lang.c                          | 107 ++++-------
 gdb/common/function-view.h              | 320 +++++++++++++++++++++++++++++++
 gdb/compile/compile-c-support.c         |  16 +-
 gdb/dwarf2read.c                        |  51 +++--
 gdb/language.h                          |  19 +-
 gdb/linespec.c                          | 315 ++++++++++++++----------------
 gdb/macrocmd.c                          |  31 ++-
 gdb/macrotab.c                          |  17 +-
 gdb/macrotab.h                          |  39 ++--
 gdb/psymtab.c                           |  79 ++++----
 gdb/symfile-debug.c                     |  42 ++--
 gdb/symfile.c                           |  13 +-
 gdb/symfile.h                           |  64 +++----
 gdb/symmisc.c                           |  47 ++---
 gdb/symtab.c                            | 329 ++++++++++----------------------
 gdb/symtab.h                            |  33 ++--
 gdb/unittests/function-view-selftests.c | 183 ++++++++++++++++++
 18 files changed, 1002 insertions(+), 727 deletions(-)
 create mode 100644 gdb/common/function-view.h
 create mode 100644 gdb/unittests/function-view-selftests.c

-- 
2.5.5


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