locations.rst revision 1.1.1.1
1.. Copyright (C) 2014-2015 Free Software Foundation, Inc. 2 Originally contributed by David Malcolm <dmalcolm@redhat.com> 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 <http://www.gnu.org/licenses/>. 17 18.. default-domain:: c 19 20Source Locations 21================ 22 23.. type:: gcc_jit_location 24 25 A `gcc_jit_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 `gcc_jit_location` instances are optional: you can always pass NULL to 31 any API entrypoint accepting one. 32 33 You can construct them using :c:func:`gcc_jit_context_new_location`. 34 35 You need to enable :c:macro:`GCC_JIT_BOOL_OPTION_DEBUGINFO` on the 36 :c:type:`gcc_jit_context` for these locations to actually be usable by 37 the debugger: 38 39 .. code-block:: c 40 41 gcc_jit_context_set_bool_option ( 42 ctxt, 43 GCC_JIT_BOOL_OPTION_DEBUGINFO, 44 1); 45 46.. function:: gcc_jit_location *\ 47 gcc_jit_context_new_location (gcc_jit_context *ctxt,\ 48 const char *filename,\ 49 int line,\ 50 int column) 51 52 Create a `gcc_jit_location` instance representing the given source 53 location. 54 55 The parameter ``filename`` must be non-NULL. The call takes a copy of 56 the underlying string, so it is valid to pass in a pointer to an 57 on-stack buffer. 58 59Faking it 60--------- 61If you don't have source code for your internal representation, but need 62to debug, you can generate a C-like representation of the functions in 63your context using :c:func:`gcc_jit_context_dump_to_file()`: 64 65.. code-block:: c 66 67 gcc_jit_context_dump_to_file (ctxt, "/tmp/something.c", 68 1 /* update_locations */); 69 70This will dump C-like code to the given path. If the `update_locations` 71argument is true, this will also set up `gcc_jit_location` information 72throughout the context, pointing at the dump file as if it were a source 73file, giving you *something* you can step through in the debugger. 74