]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/namespace.c
Fix regression on aarch64-linux gdbserver
[thirdparty/binutils-gdb.git] / gdb / namespace.c
CommitLineData
22cee43f 1/* Code dealing with "using" directives for GDB.
1d506c26 2 Copyright (C) 2003-2024 Free Software Foundation, Inc.
22cee43f
PMR
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
22cee43f 19#include "namespace.h"
68ce1575 20#include "frame.h"
83b6e1f1 21#include "symtab.h"
22cee43f
PMR
22
23/* Add a using directive to USING_DIRECTIVES. If the using directive
24 in question has already been added, don't add it twice.
25
26 Create a new struct using_direct which imports the namespace SRC
27 into the scope DEST. ALIAS is the name of the imported namespace
28 in the current scope. If ALIAS is NULL then the namespace is known
29 by its original name. DECLARATION is the name if the imported
12406b2c
TT
30 variable if this is a declaration import (Eg. using A::x),
31 otherwise it is NULL. EXCLUDES is a list of names not to import
32 from an imported module or NULL. For EXCLUDES the contents of the
33 vector are copied, but the pointed to characters are not
34 copied. */
22cee43f
PMR
35
36void
37add_using_directive (struct using_direct **using_directives,
38 const char *dest,
39 const char *src,
40 const char *alias,
41 const char *declaration,
eb1e02fd 42 const std::vector<const char *> &excludes,
68ce1575 43 unsigned int decl_line,
22cee43f
PMR
44 struct obstack *obstack)
45{
46 struct using_direct *current;
47 struct using_direct *newobj;
224c3ddb 48 int alloc_len;
22cee43f
PMR
49
50 /* Has it already been added? */
51
52 for (current = *using_directives; current != NULL; current = current->next)
53 {
54 int ix;
22cee43f
PMR
55
56 if (strcmp (current->import_src, src) != 0)
57 continue;
58 if (strcmp (current->import_dest, dest) != 0)
59 continue;
60 if ((alias == NULL && current->alias != NULL)
61 || (alias != NULL && current->alias == NULL)
62 || (alias != NULL && current->alias != NULL
63 && strcmp (alias, current->alias) != 0))
64 continue;
65 if ((declaration == NULL && current->declaration != NULL)
66 || (declaration != NULL && current->declaration == NULL)
67 || (declaration != NULL && current->declaration != NULL
68 && strcmp (declaration, current->declaration) != 0))
69 continue;
70
71 /* Compare the contents of EXCLUDES. */
eb1e02fd 72 for (ix = 0; ix < excludes.size (); ++ix)
22cee43f 73 if (current->excludes[ix] == NULL
eb1e02fd 74 || strcmp (excludes[ix], current->excludes[ix]) != 0)
22cee43f 75 break;
eb1e02fd 76 if (ix < excludes.size () || current->excludes[ix] != NULL)
22cee43f
PMR
77 continue;
78
68ce1575
BL
79 if (decl_line != current->decl_line)
80 continue;
81
22cee43f
PMR
82 /* Parameters exactly match CURRENT. */
83 return;
84 }
85
224c3ddb 86 alloc_len = (sizeof(*newobj)
eb1e02fd 87 + (excludes.size () * sizeof(*newobj->excludes)));
224c3ddb 88 newobj = (struct using_direct *) obstack_alloc (obstack, alloc_len);
22cee43f
PMR
89 memset (newobj, 0, sizeof (*newobj));
90
12406b2c
TT
91 newobj->import_src = src;
92 newobj->import_dest = dest;
93 newobj->alias = alias;
94 newobj->declaration = declaration;
22cee43f 95
10657c04
TT
96 if (!excludes.empty ())
97 memcpy (newobj->excludes, excludes.data (),
98 excludes.size () * sizeof (*newobj->excludes));
eb1e02fd 99 newobj->excludes[excludes.size ()] = NULL;
22cee43f 100
68ce1575
BL
101 newobj->decl_line = decl_line;
102
22cee43f
PMR
103 newobj->next = *using_directives;
104 *using_directives = newobj;
105}
68ce1575
BL
106
107/* See namespace.h. */
108
109bool
110using_direct::valid_line (unsigned int boundary) const
111{
112 try
113 {
114 CORE_ADDR curr_pc = get_frame_pc (get_selected_frame (nullptr));
115 symtab_and_line curr_sal = find_pc_line (curr_pc, 0);
116 return (decl_line <= curr_sal.line)
117 || (decl_line >= boundary);
118 }
119 catch (const gdb_exception &ex)
120 {
121 return true;
122 }
123}