]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/linux-tdep.c
* win32-low.c (win32_add_one_solib): If the dll name is
[thirdparty/binutils-gdb.git] / gdb / linux-tdep.c
1 /* Target-dependent code for GNU/Linux, architecture independent.
2
3 Copyright (C) 2009 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 "gdbcore.h"
22 #include "gdbtypes.h"
23 #include "linux-tdep.h"
24 #include "observer.h"
25 #include "auxv.h"
26 #include "target.h"
27 #include "elf-bfd.h"
28 #include "elf/common.h"
29
30 /* This function is suitable for architectures that don't
31 extend/override the standard siginfo structure. */
32
33 struct type *
34 linux_get_siginfo_type (struct gdbarch *gdbarch)
35 {
36 struct type *int_type, *uint_type, *long_type, *void_ptr_type;
37 struct type *uid_type, *pid_type;
38 struct type *sigval_type, *clock_type;
39 struct type *siginfo_type, *sifields_type;
40 struct type *type;
41
42 int_type = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
43 0, "int");
44 uint_type = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
45 1, "unsigned int");
46 long_type = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
47 0, "long");
48 void_ptr_type = lookup_pointer_type (builtin_type (gdbarch)->builtin_void);
49
50 /* sival_t */
51 sigval_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
52 TYPE_NAME (sigval_type) = xstrdup ("sigval_t");
53 append_composite_type_field (sigval_type, "sival_int", int_type);
54 append_composite_type_field (sigval_type, "sival_ptr", void_ptr_type);
55
56 /* __pid_t */
57 pid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF, TYPE_LENGTH (int_type),
58 xstrdup ("__pid_t"));
59 TYPE_TARGET_TYPE (pid_type) = int_type;
60 TYPE_TARGET_STUB (pid_type) = 1;
61
62 /* __uid_t */
63 uid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF, TYPE_LENGTH (uint_type),
64 xstrdup ("__uid_t"));
65 TYPE_TARGET_TYPE (uid_type) = uint_type;
66 TYPE_TARGET_STUB (uid_type) = 1;
67
68 /* __clock_t */
69 clock_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF, TYPE_LENGTH (long_type),
70 xstrdup ("__clock_t"));
71 TYPE_TARGET_TYPE (clock_type) = long_type;
72 TYPE_TARGET_STUB (clock_type) = 1;
73
74 /* _sifields */
75 sifields_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
76
77 {
78 const int si_max_size = 128;
79 int si_pad_size;
80 int size_of_int = gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT;
81
82 /* _pad */
83 if (gdbarch_ptr_bit (gdbarch) == 64)
84 si_pad_size = (si_max_size / size_of_int) - 4;
85 else
86 si_pad_size = (si_max_size / size_of_int) - 3;
87 append_composite_type_field (sifields_type, "_pad",
88 init_vector_type (int_type, si_pad_size));
89 }
90
91 /* _kill */
92 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
93 append_composite_type_field (type, "si_pid", pid_type);
94 append_composite_type_field (type, "si_uid", uid_type);
95 append_composite_type_field (sifields_type, "_kill", type);
96
97 /* _timer */
98 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
99 append_composite_type_field (type, "si_tid", int_type);
100 append_composite_type_field (type, "si_overrun", int_type);
101 append_composite_type_field (type, "si_sigval", sigval_type);
102 append_composite_type_field (sifields_type, "_timer", type);
103
104 /* _rt */
105 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
106 append_composite_type_field (type, "si_pid", pid_type);
107 append_composite_type_field (type, "si_uid", uid_type);
108 append_composite_type_field (type, "si_sigval", sigval_type);
109 append_composite_type_field (sifields_type, "_rt", type);
110
111 /* _sigchld */
112 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
113 append_composite_type_field (type, "si_pid", pid_type);
114 append_composite_type_field (type, "si_uid", uid_type);
115 append_composite_type_field (type, "si_status", int_type);
116 append_composite_type_field (type, "si_utime", clock_type);
117 append_composite_type_field (type, "si_stime", clock_type);
118 append_composite_type_field (sifields_type, "_sigchld", type);
119
120 /* _sigfault */
121 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
122 append_composite_type_field (type, "si_addr", void_ptr_type);
123 append_composite_type_field (sifields_type, "_sigfault", type);
124
125 /* _sigpoll */
126 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
127 append_composite_type_field (type, "si_band", long_type);
128 append_composite_type_field (type, "si_fd", int_type);
129 append_composite_type_field (sifields_type, "_sigpoll", type);
130
131 /* struct siginfo */
132 siginfo_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
133 TYPE_NAME (siginfo_type) = xstrdup ("siginfo");
134 append_composite_type_field (siginfo_type, "si_signo", int_type);
135 append_composite_type_field (siginfo_type, "si_errno", int_type);
136 append_composite_type_field (siginfo_type, "si_code", int_type);
137 append_composite_type_field_aligned (siginfo_type,
138 "_sifields", sifields_type,
139 TYPE_LENGTH (long_type));
140
141 return siginfo_type;
142 }
143
144 int
145 linux_has_shared_address_space (void)
146 {
147 /* Determine whether we are running on uClinux or normal Linux
148 kernel. */
149 CORE_ADDR dummy;
150 int target_is_uclinux;
151
152 target_is_uclinux
153 = (target_auxv_search (&current_target, AT_NULL, &dummy) > 0
154 && target_auxv_search (&current_target, AT_PAGESZ, &dummy) == 0);
155
156 return target_is_uclinux;
157 }
158
159 /* Observer for the executable_changed event, to check whether the new
160 exec binary is a PIE (Position Independent Executable) specimen, which
161 is currently unsupported. */
162
163 static void
164 check_is_pie_binary (void)
165 {
166 Elf_Internal_Ehdr *elf_hdr;
167
168 if (!exec_bfd)
169 return;
170 else if (bfd_get_flavour (exec_bfd) != bfd_target_elf_flavour)
171 return;
172
173 if (elf_tdata (exec_bfd)->elf_header->e_type == ET_DYN)
174 warning (_("\
175 The current binary is a PIE (Position Independent Executable), which\n\
176 GDB does NOT currently support. Most debugger features will fail if used\n\
177 in this session.\n"));
178 }
179
180 /* Provide a prototype to silence -Wmissing-prototypes. */
181 extern initialize_file_ftype _initialize_linux_tdep;
182
183 void
184 _initialize_linux_tdep (void)
185 {
186 observer_attach_executable_changed (check_is_pie_binary);
187 }