Branch data Line data Source code
1 : : /* Find line information for a given macro. 2 : : Copyright (C) 2014 Red Hat, Inc. 3 : : This file is part of elfutils. 4 : : 5 : : This file is free software; you can redistribute it and/or modify 6 : : it under the terms of either 7 : : 8 : : * the GNU Lesser General Public License as published by the Free 9 : : Software Foundation; either version 3 of the License, or (at 10 : : your option) any later version 11 : : 12 : : or 13 : : 14 : : * the GNU General Public License as published by the Free 15 : : Software Foundation; either version 2 of the License, or (at 16 : : your option) any later version 17 : : 18 : : or both in parallel, as here. 19 : : 20 : : elfutils is distributed in the hope that it will be useful, but 21 : : WITHOUT ANY WARRANTY; without even the implied warranty of 22 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 : : General Public License for more details. 24 : : 25 : : You should have received copies of the GNU General Public License and 26 : : the GNU Lesser General Public License along with this program. If 27 : : not, see <http://www.gnu.org/licenses/>. */ 28 : : 29 : : #ifdef HAVE_CONFIG_H 30 : : # include <config.h> 31 : : #endif 32 : : 33 : : #include "libdwP.h" 34 : : 35 : : int 36 : 13 : dwarf_macro_getsrcfiles (Dwarf *dbg, Dwarf_Macro *macro, 37 : : Dwarf_Files **files, size_t *nfiles) 38 : : { 39 : : /* macro is declared NN */ 40 : 13 : Dwarf_Macro_Op_Table *const table = macro->table; 41 [ + + ]: 13 : if (table->files == NULL) 42 : : { 43 : 4 : Dwarf_Off line_offset = table->line_offset; 44 [ - + ]: 4 : if (line_offset == (Dwarf_Off) -1) 45 : : { 46 : 0 : *files = NULL; 47 : 0 : *nfiles = 0; 48 : 0 : return 0; 49 : : } 50 : : 51 : : /* If TABLE->comp_dir is NULL that could mean any of the 52 : : following: 53 : : 54 : : - The macro unit is not bound to a CU. It's an auxiliary 55 : : unit used purely for import from other units. In that case 56 : : there's actually no COMP_DIR value that we could use. 57 : : 58 : : - The macro unit is bound to a CU, but there's no 59 : : DW_AT_comp_dir attribute at the CU DIE. 60 : : 61 : : - The macro unit is bound to a CU, but we don't know that, 62 : : likely because its iteration was requested through 63 : : dwarf_getmacros_off interface. This might be legitimate if 64 : : one macro unit imports another CU's macro unit, but that is 65 : : unlikely to happen in practice. Most probably this is not 66 : : legitimate use of the interfaces. 67 : : 68 : : So when the interfaces are used correctly, COMP_DIR value is 69 : : always right. That means that we can cache the parsed 70 : : .debug_line unit without fear that later on someone requests 71 : : the same unit through dwarf_getsrcfiles, and the file names 72 : : will be broken. */ 73 : : 74 [ - + ]: 4 : if (__libdw_getsrclines (dbg, line_offset, table->comp_dir, 75 [ + + ]: 4 : table->is_64bit ? 8 : 4, 76 : : NULL, &table->files) < 0) 77 : 0 : table->files = (void *) -1; 78 : : } 79 : : 80 [ + - ]: 13 : if (table->files == (void *) -1) 81 : : return -1; 82 : : 83 : 13 : *files = table->files; 84 : 13 : *nfiles = table->files->nfiles; 85 : 13 : return 0; 86 : : }