Background : CTF is the Compact Ansi-C Type Format. It is a format designed to express some characteristics (specifically Type information) of the data types in a C program. CTF format is compact and fast; It was originally designed for use-cases like dynamic tracing, online in-application debugging among others.
A patch to the binutils mailing list to add libctf is currently under review (https://sourceware.org/ml/binutils/2019-05/msg00154.html and https://sourceware.org/ml/binutils/2019-05/msg00212.html). libctf provides means to create, update, read and manipulate CTF information. This GCC patch set is preliminary work and the purpose is to gather comments and feedback about CTF support in GCC. (For technical introduction into the CTF format, the CTF header or https://sourceware.org/ml/binutils/2019-04/msg00277.html will be useful.) Project Details : The project aims to add the support for CTF in the GNU toolchain. Adding CTF support in the GNU toolchain will help the community in developing and converging the tools and use-cases where a light-weight debug format is needed. De-duplication is a key aspect of the CTF format which ensures its compactness. A parallel effort is ongoing to support de-duplication of CTF types at the link-time. In phase 1, we are making the compiler, linker and the debugger (GDB) capable of handling the CTF format. CTF format, in its present form, does not have callsite information. We are working on this as well. Once the CTF format extensions are agreed upon, the -gt1 option (see below) will begin to take form, in phase 2 of the project. GCC RFC patch set : Patch 1 is a simple addition of a new function lang_GNU_GIMPLE to check for GIMPLE frontend. Patch 2 and Patch 3 set up the framework for CTF support in GCC : -- Patch 2 adds the new command line option for generating CTF. CTF generation is enabled in the compiler by specifying an explicit -gt or -gtLEVEL[LEVEL=1,2] : -gtLEVEL This is used to request CTF debug information and to specify how much CTF debug information, LEVEL[=0,1,2] can be specified. If -gt is specified (with no LEVEL), the default value of LEVEL is 2. -gt0 (Level 0) produces no CTF debug information at all. Thus, -gt0 negates -gt. -gt1 (Level 1) produces CTF information for tracebacks only. This includes CTF callsite information, but does not include type information for other entities. -gt2 (Level 2) produces type information for entities (functions, variables etc.) at file-scope or global-scope only. This level of information can be used by dynamic tracers like DTrace. -- Patch 3 adds the CTF debug hooks and initializes them if the required user-level options are specified. CTF debug hooks are wrappers around the DWARF debug hooks. One of the main high-level design requirements that is relevant in the context of the current GCC patch set is that - CTF and DWARF must be able to co-exist. A user may want CTF debug information in isolation or with other debug formats. A .ctf section is small and unlike other debug sections, ideally should not need to be stripped out of the binary/executable. High-level proposed plan (phase 1) : In the next few patches, the functionality to generate contents of the CTF section (.ctf) for a single compilation unit will be added. Once CTF generation for a single compilation unit stabilizes, LTO and CTF generation will be looked at. Feedback and suggestions welcome. Thanks Indu Bhagat (3): Add new function lang_GNU_GIMPLE Add CTF command line options : -gtLEVEL Create CTF debug hooks gcc/ChangeLog | 24 ++ gcc/Makefile.in | 3 + gcc/common.opt | 9 + gcc/ctfout.c | 171 +++++++++ gcc/ctfout.h | 41 +++ gcc/debug.h | 4 + gcc/doc/invoke.texi | 16 + gcc/flag-types.h | 13 + gcc/gengtype.c | 4 +- gcc/langhooks.c | 9 + gcc/langhooks.h | 1 + gcc/opts.c | 26 ++ gcc/testsuite/ChangeLog | 7 + gcc/testsuite/gcc.dg/debug/ctf/ctf-1.c | 6 + gcc/testsuite/gcc.dg/debug/ctf/ctf-preamble-1.c | 11 + gcc/testsuite/gcc.dg/debug/ctf/ctf.exp | 41 +++ gcc/testsuite/gcc.dg/debug/dwarf2-ctf-1.c | 7 + gcc/toplev.c | 24 ++ include/ChangeLog | 4 + include/ctf.h | 471 ++++++++++++++++++++++++ 20 files changed, 890 insertions(+), 2 deletions(-) create mode 100644 gcc/ctfout.c create mode 100644 gcc/ctfout.h create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-1.c create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-preamble-1.c create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf.exp create mode 100644 gcc/testsuite/gcc.dg/debug/dwarf2-ctf-1.c create mode 100644 include/ctf.h -- 1.8.3.1