From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29838 invoked by alias); 22 Feb 2017 14:50:38 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 29806 invoked by uid 89); 22 Feb 2017 14:50:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=hitting X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 22 Feb 2017 14:50:36 +0000 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 533813D960 for ; Wed, 22 Feb 2017 14:50:36 +0000 (UTC) Received: from cascais.lan (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id D198E97D26 for ; Wed, 22 Feb 2017 14:50:35 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 0/3] Introduce gdb::function_view & fix completion bug Date: Wed, 22 Feb 2017 14:50:00 -0000 Message-Id: <1487775033-32699-1-git-send-email-palves@redhat.com> X-SW-Source: 2017-02/txt/msg00591.txt.bz2 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