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 dwarf_macro_getsrcfiles (Dwarf *dbg, Dwarf_Macro *macro, 37 Dwarf_Files **files, size_t *nfiles) 38 { 39 if (macro == NULL) 40 return -1; 41 42 Dwarf_Macro_Op_Table *const table = macro->table; 43 if (table->files == NULL) 44 { 45 Dwarf_Off line_offset = table->line_offset; 46 if (line_offset == (Dwarf_Off) -1) 47 { 48 *files = NULL; 49 *nfiles = 0; 50 return 0; 51 } 52 53 /* If TABLE->comp_dir is NULL that could mean any of the 54 following: 55 56 - The macro unit is not bound to a CU. It's an auxiliary 57 unit used purely for import from other units. In that case 58 there's actually no COMP_DIR value that we could use. 59 60 - The macro unit is bound to a CU, but there's no 61 DW_AT_comp_dir attribute at the CU DIE. 62 63 - The macro unit is bound to a CU, but we don't know that, 64 likely because its iteration was requested through 65 dwarf_getmacros_off interface. This might be legitimate if 66 one macro unit imports another CU's macro unit, but that is 67 unlikely to happen in practice. Most probably this is not 68 legitimate use of the interfaces. 69 70 So when the interfaces are used correctly, COMP_DIR value is 71 always right. That means that we can cache the parsed 72 .debug_line unit without fear that later on someone requests 73 the same unit through dwarf_getsrcfiles, and the file names 74 will be broken. */ 75 76 if (__libdw_getsrclines (dbg, line_offset, table->comp_dir, 77 table->is_64bit ? 8 : 4, 78 NULL, &table->files) < 0) 79 table->files = (void *) -1; 80 } 81 82 if (table->files == (void *) -1) 83 return -1; 84 85 *files = table->files; 86 *nfiles = table->files->nfiles; 87 return 0; 88 } 89