2015-01-15 Richard Sandiford <richard.sandiford@arm.com>
[official-gcc.git] / gcc / jit / docs / cp / topics / locations.rst
blob8e0848deab6de47120673ca8ca67c3af1ec688d9
1 .. Copyright (C) 2014-2015 Free Software Foundation, Inc.
2    Originally contributed by David Malcolm <dmalcolm@redhat.com>
4    This is free software: you can redistribute it and/or modify it
5    under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
9    This program is distributed in the hope that it will be useful, but
10    WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    General Public License for more details.
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see
16    <http://www.gnu.org/licenses/>.
18 .. default-domain:: cpp
20 Source Locations
21 ================
23 .. class:: gccjit::location
25    A `gccjit::location` encapsulates a source code location, so that
26    you can (optionally) associate locations in your language with
27    statements in the JIT-compiled code, allowing the debugger to
28    single-step through your language.
30    `gccjit::location` instances are optional: you can always omit them
31    from any C++ API entrypoint accepting one.
33    You can construct them using :func:`gccjit::context::new_location`.
35    You need to enable :c:macro:`GCC_JIT_BOOL_OPTION_DEBUGINFO` on the
36    :class:`gccjit::context` for these locations to actually be usable by
37    the debugger:
39    .. code-block:: cpp
41      ctxt.set_bool_option (GCC_JIT_BOOL_OPTION_DEBUGINFO, 1);
43 .. function:: gccjit::location \
44               gccjit::context::new_location (const char *filename, \
45                                              int line, \
46                                              int column)
48    Create a `gccjit::location` instance representing the given source
49    location.
51 Faking it
52 ---------
53 If you don't have source code for your internal representation, but need
54 to debug, you can generate a C-like representation of the functions in
55 your context using :func:`gccjit::context::dump_to_file()`:
57 .. code-block:: cpp
59   ctxt.dump_to_file ("/tmp/something.c",
60                      1 /* update_locations */);
62 This will dump C-like code to the given path.  If the `update_locations`
63 argument is true, this will also set up `gccjit::location` information
64 throughout the context, pointing at the dump file as if it were a source
65 file, giving you *something* you can step through in the debugger.