| 1 |
.. Copyright (C) 2014-2025 Free Software Foundation, Inc. |
| 2 |
Originally contributed by David Malcolm <[email protected]> |
| 3 |
|
| 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. |
| 8 |
|
| 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. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public License |
| 15 |
along with this program. If not, see |
| 16 |
<https://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
.. default-domain:: cpp |
| 19 |
|
| 20 |
Source Locations |
| 21 |
================ |
| 22 |
|
| 23 |
.. class:: gccjit::location |
| 24 |
|
| 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. |
| 29 |
|
| 30 |
`gccjit::location` instances are optional: you can always omit them |
| 31 |
from any C++ API entrypoint accepting one. |
| 32 |
|
| 33 |
You can construct them using :func:`gccjit::context::new_location`. |
| 34 |
|
| 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: |
| 38 |
|
| 39 |
.. code-block:: cpp |
| 40 |
|
| 41 |
ctxt.set_bool_option (GCC_JIT_BOOL_OPTION_DEBUGINFO, 1); |
| 42 |
|
| 43 |
.. function:: gccjit::location \ |
| 44 |
gccjit::context::new_location (const char *filename, \ |
| 45 |
int line, \ |
| 46 |
int column) |
| 47 |
|
| 48 |
Create a `gccjit::location` instance representing the given source |
| 49 |
location. |
| 50 |
|
| 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()`: |
| 56 |
|
| 57 |
.. code-block:: cpp |
| 58 |
|
| 59 |
ctxt.dump_to_file ("/tmp/something.c", |
| 60 |
1 /* update_locations */); |
| 61 |
|
| 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. |