Home | History | Annotate | Line # | Download | only in topics
      1  1.7  mrg .. Copyright (C) 2014-2022 Free Software Foundation, Inc.
      2  1.1  mrg    Originally contributed by David Malcolm <dmalcolm (a] redhat.com>
      3  1.1  mrg 
      4  1.1  mrg    This is free software: you can redistribute it and/or modify it
      5  1.1  mrg    under the terms of the GNU General Public License as published by
      6  1.1  mrg    the Free Software Foundation, either version 3 of the License, or
      7  1.1  mrg    (at your option) any later version.
      8  1.1  mrg 
      9  1.1  mrg    This program is distributed in the hope that it will be useful, but
     10  1.1  mrg    WITHOUT ANY WARRANTY; without even the implied warranty of
     11  1.1  mrg    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12  1.1  mrg    General Public License for more details.
     13  1.1  mrg 
     14  1.1  mrg    You should have received a copy of the GNU General Public License
     15  1.1  mrg    along with this program.  If not, see
     16  1.7  mrg    <https://www.gnu.org/licenses/>.
     17  1.1  mrg 
     18  1.1  mrg .. default-domain:: c
     19  1.1  mrg 
     20  1.1  mrg Source Locations
     21  1.1  mrg ================
     22  1.1  mrg 
     23  1.1  mrg .. type:: gcc_jit_location
     24  1.1  mrg 
     25  1.1  mrg    A `gcc_jit_location` encapsulates a source code location, so that
     26  1.1  mrg    you can (optionally) associate locations in your language with
     27  1.1  mrg    statements in the JIT-compiled code, allowing the debugger to
     28  1.1  mrg    single-step through your language.
     29  1.1  mrg 
     30  1.1  mrg    `gcc_jit_location` instances are optional: you can always pass NULL to
     31  1.1  mrg    any API entrypoint accepting one.
     32  1.1  mrg 
     33  1.1  mrg    You can construct them using :c:func:`gcc_jit_context_new_location`.
     34  1.1  mrg 
     35  1.1  mrg    You need to enable :c:macro:`GCC_JIT_BOOL_OPTION_DEBUGINFO` on the
     36  1.1  mrg    :c:type:`gcc_jit_context` for these locations to actually be usable by
     37  1.1  mrg    the debugger:
     38  1.1  mrg 
     39  1.1  mrg    .. code-block:: c
     40  1.1  mrg 
     41  1.1  mrg      gcc_jit_context_set_bool_option (
     42  1.1  mrg        ctxt,
     43  1.1  mrg        GCC_JIT_BOOL_OPTION_DEBUGINFO,
     44  1.1  mrg        1);
     45  1.1  mrg 
     46  1.1  mrg .. function:: gcc_jit_location *\
     47  1.1  mrg               gcc_jit_context_new_location (gcc_jit_context *ctxt,\
     48  1.1  mrg                                             const char *filename,\
     49  1.1  mrg                                             int line,\
     50  1.1  mrg                                             int column)
     51  1.1  mrg 
     52  1.1  mrg    Create a `gcc_jit_location` instance representing the given source
     53  1.1  mrg    location.
     54  1.1  mrg 
     55  1.1  mrg    The parameter ``filename`` must be non-NULL.  The call takes a copy of
     56  1.1  mrg    the underlying string, so it is valid to pass in a pointer to an
     57  1.1  mrg    on-stack buffer.
     58  1.1  mrg 
     59  1.1  mrg Faking it
     60  1.1  mrg ---------
     61  1.1  mrg If you don't have source code for your internal representation, but need
     62  1.1  mrg to debug, you can generate a C-like representation of the functions in
     63  1.1  mrg your context using :c:func:`gcc_jit_context_dump_to_file()`:
     64  1.1  mrg 
     65  1.1  mrg .. code-block:: c
     66  1.1  mrg 
     67  1.1  mrg   gcc_jit_context_dump_to_file (ctxt, "/tmp/something.c",
     68  1.1  mrg                                 1 /* update_locations */);
     69  1.1  mrg 
     70  1.1  mrg This will dump C-like code to the given path.  If the `update_locations`
     71  1.1  mrg argument is true, this will also set up `gcc_jit_location` information
     72  1.1  mrg throughout the context, pointing at the dump file as if it were a source
     73  1.1  mrg file, giving you *something* you can step through in the debugger.
     74