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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
commit aa1ed4a93a2eb0fb90d274c15288f3aad1791f60
Author: John Baldwin <jhb@FreeBSD.org>
Date: Sun Jun 12 08:56:31 2016 -0700
Add elfcore_grok_freebsd_note to parse FreeBSD ELF core notes.
Move parsing of FreeBSD-specific ELF core notes out of elfcore_grok_note
into a new elfcore_grok_freebsd_note function. Add core note grok routines
for FreeBSD's psinfo and prstatus notes while here rather than depending
on the native handling in elfcore_grok_note.
bfd/ChangeLog:
* elf.c (elfcore_grok_note): Remove handling of NT_X86_XSTATE for
FreeBSD. Remove case for NT_FREEBSD_THRMISC.
(elfcore_grok_freebsd_psinfo): New function.
(elfcore_grok_freebsd_prstatus): New function.
(elfcore_grok_freebsd_note): New function.
(elf_parse_notes): Use "elfcore_grok_freebsd_note" for "FreeBSD"
notes.
diff --git bfd/elf.c bfd/elf.c
index aaf2b53..cfcafaa 100644
--- bfd/elf.c
+++ bfd/elf.c
@@ -9327,9 +9327,6 @@ elfcore_grok_note (bfd *abfd, Elf_Internal_Note *note)
if (note->namesz == 6
&& strcmp (note->namedata, "LINUX") == 0)
return elfcore_grok_xstatereg (abfd, note);
- else if (note->namesz == 8
- && strcmp (note->namedata, "FreeBSD") == 0)
- return elfcore_grok_xstatereg (abfd, note);
else
return TRUE;
@@ -9485,12 +9482,6 @@ elfcore_grok_note (bfd *abfd, Elf_Internal_Note *note)
return elfcore_make_note_pseudosection (abfd, ".note.linuxcore.siginfo",
note);
- case NT_FREEBSD_THRMISC:
- if (note->namesz == 8
- && strcmp (note->namedata, "FreeBSD") == 0)
- return elfcore_make_note_pseudosection (abfd, ".thrmisc", note);
- else
- return TRUE;
}
}
@@ -9556,6 +9547,134 @@ elfobj_grok_stapsdt_note (bfd *abfd, Elf_Internal_Note *note)
}
static bfd_boolean
+elfcore_grok_freebsd_psinfo (bfd *abfd, Elf_Internal_Note *note)
+{
+ size_t offset;
+
+ /* Check for version 1 in pr_version. */
+ if (bfd_h_get_32 (abfd, (bfd_byte *) note->descdata) != 1)
+ return FALSE;
+ offset = 4;
+
+ /* Skip over pr_psinfosz. */
+ switch (abfd->arch_info->bits_per_word)
+ {
+ case 32:
+ offset += 4;
+ break;
+
+ case 64:
+ offset += 4; /* Padding before pr_psinfosz. */
+ offset += 8;
+ break;
+
+ default:
+ return FALSE;
+ }
+
+ /* pr_fname is PRFNAMESZ (16) + 1 bytes in size. */
+ elf_tdata (abfd)->core->program
+ = _bfd_elfcore_strndup (abfd, note->descdata + offset, 17);
+ offset += 17;
+
+ /* pr_psargs is PRARGSZ (80) + 1 bytes in size. */
+ elf_tdata (abfd)->core->command
+ = _bfd_elfcore_strndup (abfd, note->descdata + offset, 81);
+
+ return TRUE;
+}
+
+static bfd_boolean
+elfcore_grok_freebsd_prstatus (bfd *abfd, Elf_Internal_Note *note)
+{
+ size_t offset;
+ size_t size;
+
+ /* Check for version 1 in pr_version. */
+ if (bfd_h_get_32 (abfd, (bfd_byte *) note->descdata) != 1)
+ return FALSE;
+ offset = 4;
+
+ /* Skip over pr_statussz. */
+ switch (abfd->arch_info->bits_per_word)
+ {
+ case 32:
+ offset += 4;
+ break;
+
+ case 64:
+ offset += 4; /* Padding before pr_statussz. */
+ offset += 8;
+ break;
+
+ default:
+ return FALSE;
+ }
+
+ /* Extract size of pr_reg from pr_gregsetsz. */
+ if (abfd->arch_info->bits_per_word == 32)
+ size = bfd_h_get_32 (abfd, (bfd_byte *) note->descdata + offset);
+ else
+ size = bfd_h_get_64 (abfd, (bfd_byte *) note->descdata + offset);
+
+ /* Skip over pr_gregsetsz and pr_fpregsetsz. */
+ offset += (abfd->arch_info->bits_per_word / 8) * 2;
+
+ /* Skip over pr_osreldate. */
+ offset += 4;
+
+ /* Read signal from pr_cursig. */
+ if (elf_tdata (abfd)->core->signal == 0)
+ elf_tdata (abfd)->core->signal
+ = bfd_h_get_32 (abfd, (bfd_byte *) note->descdata + offset);
+ offset += 4;
+
+ /* Read TID from pr_pid. */
+ elf_tdata (abfd)->core->lwpid
+ = bfd_h_get_32 (abfd, (bfd_byte *) note->descdata + offset);
+ offset += 4;
+
+ /* Padding before pr_reg. */
+ if (abfd->arch_info->bits_per_word == 64)
+ offset += 4;
+
+ /* Make a ".reg/999" section and a ".reg" section. */
+ return _bfd_elfcore_make_pseudosection (abfd, ".reg",
+ size, note->descpos + offset);
+}
+
+static bfd_boolean
+elfcore_grok_freebsd_note (bfd *abfd, Elf_Internal_Note *note)
+{
+ switch (note->type)
+ {
+ case NT_PRSTATUS:
+ return elfcore_grok_freebsd_prstatus (abfd, note);
+
+ case NT_FPREGSET:
+ return elfcore_grok_prfpreg (abfd, note);
+
+ case NT_PRPSINFO:
+ return elfcore_grok_freebsd_psinfo (abfd, note);
+
+ case NT_FREEBSD_THRMISC:
+ if (note->namesz == 8)
+ return elfcore_make_note_pseudosection (abfd, ".thrmisc", note);
+ else
+ return TRUE;
+
+ case NT_X86_XSTATE:
+ if (note->namesz == 8)
+ return elfcore_grok_xstatereg (abfd, note);
+ else
+ return TRUE;
+
+ default:
+ return TRUE;
+ }
+}
+
+static bfd_boolean
elfcore_netbsd_get_lwpid (Elf_Internal_Note *note, int *lwpidp)
{
char *cp;
@@ -10467,6 +10586,7 @@ elf_parse_notes (bfd *abfd, char *buf, size_t size, file_ptr offset)
grokers[] =
{
GROKER_ELEMENT ("", elfcore_grok_note),
+ GROKER_ELEMENT ("FreeBSD", elfcore_grok_freebsd_note),
GROKER_ELEMENT ("NetBSD-CORE", elfcore_grok_netbsd_note),
GROKER_ELEMENT ( "OpenBSD", elfcore_grok_openbsd_note),
GROKER_ELEMENT ("QNX", elfcore_grok_nto_note),
|