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