Create dwarf2/comp-unit.[ch]
[deliverable/binutils-gdb.git] / gdb / dwarf2 / line-header.c
1 /* DWARF 2 debugging format support for GDB.
2
3 Copyright (C) 1994-2020 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "dwarf2/line-header.h"
22 #include "dwarf2/read.h"
23 #include "complaints.h"
24 #include "filenames.h"
25
26 void
27 line_header::add_include_dir (const char *include_dir)
28 {
29 if (dwarf_line_debug >= 2)
30 {
31 size_t new_size;
32 if (version >= 5)
33 new_size = m_include_dirs.size ();
34 else
35 new_size = m_include_dirs.size () + 1;
36 fprintf_unfiltered (gdb_stdlog, "Adding dir %zu: %s\n",
37 new_size, include_dir);
38 }
39 m_include_dirs.push_back (include_dir);
40 }
41
42 void
43 line_header::add_file_name (const char *name,
44 dir_index d_index,
45 unsigned int mod_time,
46 unsigned int length)
47 {
48 if (dwarf_line_debug >= 2)
49 {
50 size_t new_size;
51 if (version >= 5)
52 new_size = file_names_size ();
53 else
54 new_size = file_names_size () + 1;
55 fprintf_unfiltered (gdb_stdlog, "Adding file %zu: %s\n",
56 new_size, name);
57 }
58 m_file_names.emplace_back (name, d_index, mod_time, length);
59 }
60
61 gdb::unique_xmalloc_ptr<char>
62 line_header::file_file_name (int file)
63 {
64 /* Is the file number a valid index into the line header's file name
65 table? Remember that file numbers start with one, not zero. */
66 if (is_valid_file_index (file))
67 {
68 const file_entry *fe = file_name_at (file);
69
70 if (!IS_ABSOLUTE_PATH (fe->name))
71 {
72 const char *dir = fe->include_dir (this);
73 if (dir != NULL)
74 return gdb::unique_xmalloc_ptr<char> (concat (dir, SLASH_STRING,
75 fe->name,
76 (char *) NULL));
77 }
78 return make_unique_xstrdup (fe->name);
79 }
80 else
81 {
82 /* The compiler produced a bogus file number. We can at least
83 record the macro definitions made in the file, even if we
84 won't be able to find the file by name. */
85 char fake_name[80];
86
87 xsnprintf (fake_name, sizeof (fake_name),
88 "<bad macro file number %d>", file);
89
90 complaint (_("bad file number in macro information (%d)"),
91 file);
92
93 return make_unique_xstrdup (fake_name);
94 }
95 }
96
97 gdb::unique_xmalloc_ptr<char>
98 line_header::file_full_name (int file, const char *comp_dir)
99 {
100 /* Is the file number a valid index into the line header's file name
101 table? Remember that file numbers start with one, not zero. */
102 if (is_valid_file_index (file))
103 {
104 gdb::unique_xmalloc_ptr<char> relative = file_file_name (file);
105
106 if (IS_ABSOLUTE_PATH (relative.get ()) || comp_dir == NULL)
107 return relative;
108 return gdb::unique_xmalloc_ptr<char> (concat (comp_dir, SLASH_STRING,
109 relative.get (),
110 (char *) NULL));
111 }
112 else
113 return file_file_name (file);
114 }
This page took 0.031804 seconds and 4 git commands to generate.