OLD | NEW |
1 /* Target-dependent code for GNU/Linux, architecture independent. | 1 /* Target-dependent code for GNU/Linux, architecture independent. |
2 | 2 |
3 Copyright (C) 2009-2012 Free Software Foundation, Inc. | 3 Copyright (C) 2009-2012 Free Software Foundation, Inc. |
4 | 4 |
5 This file is part of GDB. | 5 This file is part of GDB. |
6 | 6 |
7 This program is free software; you can redistribute it and/or modify | 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 | 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 | 9 the Free Software Foundation; either version 3 of the License, or |
10 (at your option) any later version. | 10 (at your option) any later version. |
11 | 11 |
12 This program is distributed in the hope that it will be useful, | 12 This program is distributed in the hope that it will be useful, |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 GNU General Public License for more details. | 15 GNU General Public License for more details. |
16 | 16 |
17 You should have received a copy of the GNU General Public License | 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/>. */ | 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
19 | 19 |
20 #include "defs.h" | 20 #include "defs.h" |
21 #include "gdbtypes.h" | 21 #include "gdbtypes.h" |
22 #include "linux-tdep.h" | 22 #include "linux-tdep.h" |
23 #include "auxv.h" | 23 #include "auxv.h" |
24 #include "target.h" | 24 #include "target.h" |
| 25 #include "gdbthread.h" |
| 26 #include "gdbcore.h" |
| 27 #include "regcache.h" |
| 28 #include "regset.h" |
25 #include "elf/common.h" | 29 #include "elf/common.h" |
| 30 #include "elf-bfd.h" /* for elfcore_write_* */ |
26 #include "inferior.h" | 31 #include "inferior.h" |
| 32 #include "cli/cli-utils.h" |
| 33 |
| 34 #include <ctype.h> |
27 | 35 |
28 static struct gdbarch_data *linux_gdbarch_data_handle; | 36 static struct gdbarch_data *linux_gdbarch_data_handle; |
29 | 37 |
30 struct linux_gdbarch_data | 38 struct linux_gdbarch_data |
31 { | 39 { |
32 struct type *siginfo_type; | 40 struct type *siginfo_type; |
33 }; | 41 }; |
34 | 42 |
35 static void * | 43 static void * |
36 init_linux_gdbarch_data (struct gdbarch *gdbarch) | 44 init_linux_gdbarch_data (struct gdbarch *gdbarch) |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 append_composite_type_field (siginfo_type, "si_code", int_type); | 166 append_composite_type_field (siginfo_type, "si_code", int_type); |
159 append_composite_type_field_aligned (siginfo_type, | 167 append_composite_type_field_aligned (siginfo_type, |
160 "_sifields", sifields_type, | 168 "_sifields", sifields_type, |
161 TYPE_LENGTH (long_type)); | 169 TYPE_LENGTH (long_type)); |
162 | 170 |
163 linux_gdbarch_data->siginfo_type = siginfo_type; | 171 linux_gdbarch_data->siginfo_type = siginfo_type; |
164 | 172 |
165 return siginfo_type; | 173 return siginfo_type; |
166 } | 174 } |
167 | 175 |
168 int | 176 static int |
169 linux_has_shared_address_space (void) | 177 linux_has_shared_address_space (struct gdbarch *gdbarch) |
170 { | 178 { |
171 /* Determine whether we are running on uClinux or normal Linux | 179 /* Determine whether we are running on uClinux or normal Linux |
172 kernel. */ | 180 kernel. */ |
173 CORE_ADDR dummy; | 181 CORE_ADDR dummy; |
174 int target_is_uclinux; | 182 int target_is_uclinux; |
175 | 183 |
176 target_is_uclinux | 184 target_is_uclinux |
177 = (target_auxv_search (¤t_target, AT_NULL, &dummy) > 0 | 185 = (target_auxv_search (¤t_target, AT_NULL, &dummy) > 0 |
178 && target_auxv_search (¤t_target, AT_PAGESZ, &dummy) == 0); | 186 && target_auxv_search (¤t_target, AT_PAGESZ, &dummy) == 0); |
179 | 187 |
180 return target_is_uclinux; | 188 return target_is_uclinux; |
181 } | 189 } |
182 | 190 |
183 /* This is how we want PTIDs from core files to be printed. */ | 191 /* This is how we want PTIDs from core files to be printed. */ |
184 | 192 |
185 static char * | 193 static char * |
186 linux_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid) | 194 linux_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid) |
187 { | 195 { |
188 static char buf[80]; | 196 static char buf[80]; |
189 | 197 |
190 if (ptid_get_lwp (ptid) != 0) | 198 if (ptid_get_lwp (ptid) != 0) |
191 { | 199 { |
192 snprintf (buf, sizeof (buf), "LWP %ld", ptid_get_lwp (ptid)); | 200 snprintf (buf, sizeof (buf), "LWP %ld", ptid_get_lwp (ptid)); |
193 return buf; | 201 return buf; |
194 } | 202 } |
195 | 203 |
196 return normal_pid_to_str (ptid); | 204 return normal_pid_to_str (ptid); |
197 } | 205 } |
198 | 206 |
| 207 /* Service function for corefiles and info proc. */ |
| 208 |
| 209 static void |
| 210 read_mapping (const char *line, |
| 211 ULONGEST *addr, ULONGEST *endaddr, |
| 212 const char **permissions, size_t *permissions_len, |
| 213 ULONGEST *offset, |
| 214 const char **device, size_t *device_len, |
| 215 ULONGEST *inode, |
| 216 const char **filename) |
| 217 { |
| 218 const char *p = line; |
| 219 |
| 220 *addr = strtoulst (p, &p, 16); |
| 221 if (*p == '-') |
| 222 p++; |
| 223 *endaddr = strtoulst (p, &p, 16); |
| 224 |
| 225 while (*p && isspace (*p)) |
| 226 p++; |
| 227 *permissions = p; |
| 228 while (*p && !isspace (*p)) |
| 229 p++; |
| 230 *permissions_len = p - *permissions; |
| 231 |
| 232 *offset = strtoulst (p, &p, 16); |
| 233 |
| 234 while (*p && isspace (*p)) |
| 235 p++; |
| 236 *device = p; |
| 237 while (*p && !isspace (*p)) |
| 238 p++; |
| 239 *device_len = p - *device; |
| 240 |
| 241 *inode = strtoulst (p, &p, 10); |
| 242 |
| 243 while (*p && isspace (*p)) |
| 244 p++; |
| 245 *filename = p; |
| 246 } |
| 247 |
| 248 /* Implement the "info proc" command. */ |
| 249 |
| 250 static void |
| 251 linux_info_proc (struct gdbarch *gdbarch, char *args, |
| 252 enum info_proc_what what) |
| 253 { |
| 254 /* A long is used for pid instead of an int to avoid a loss of precision |
| 255 compiler warning from the output of strtoul. */ |
| 256 long pid; |
| 257 int cmdline_f = (what == IP_MINIMAL || what == IP_CMDLINE || what == IP_ALL); |
| 258 int cwd_f = (what == IP_MINIMAL || what == IP_CWD || what == IP_ALL); |
| 259 int exe_f = (what == IP_MINIMAL || what == IP_EXE || what == IP_ALL); |
| 260 int mappings_f = (what == IP_MAPPINGS || what == IP_ALL); |
| 261 int status_f = (what == IP_STATUS || what == IP_ALL); |
| 262 int stat_f = (what == IP_STAT || what == IP_ALL); |
| 263 char filename[100]; |
| 264 gdb_byte *data; |
| 265 int target_errno; |
| 266 |
| 267 if (args && isdigit (args[0])) |
| 268 pid = strtoul (args, &args, 10); |
| 269 else |
| 270 { |
| 271 if (!target_has_execution) |
| 272 error (_("No current process: you must name one.")); |
| 273 if (current_inferior ()->fake_pid_p) |
| 274 error (_("Can't determine the current process's PID: you must name one."
)); |
| 275 |
| 276 pid = current_inferior ()->pid; |
| 277 } |
| 278 |
| 279 args = skip_spaces (args); |
| 280 if (args && args[0]) |
| 281 error (_("Too many parameters: %s"), args); |
| 282 |
| 283 printf_filtered (_("process %ld\n"), pid); |
| 284 if (cmdline_f) |
| 285 { |
| 286 xsnprintf (filename, sizeof filename, "/proc/%ld/cmdline", pid); |
| 287 data = target_fileio_read_stralloc (filename); |
| 288 if (data) |
| 289 { |
| 290 struct cleanup *cleanup = make_cleanup (xfree, data); |
| 291 printf_filtered ("cmdline = '%s'\n", data); |
| 292 do_cleanups (cleanup); |
| 293 } |
| 294 else |
| 295 warning (_("unable to open /proc file '%s'"), filename); |
| 296 } |
| 297 if (cwd_f) |
| 298 { |
| 299 xsnprintf (filename, sizeof filename, "/proc/%ld/cwd", pid); |
| 300 data = target_fileio_readlink (filename, &target_errno); |
| 301 if (data) |
| 302 { |
| 303 struct cleanup *cleanup = make_cleanup (xfree, data); |
| 304 printf_filtered ("cwd = '%s'\n", data); |
| 305 do_cleanups (cleanup); |
| 306 } |
| 307 else |
| 308 warning (_("unable to read link '%s'"), filename); |
| 309 } |
| 310 if (exe_f) |
| 311 { |
| 312 xsnprintf (filename, sizeof filename, "/proc/%ld/exe", pid); |
| 313 data = target_fileio_readlink (filename, &target_errno); |
| 314 if (data) |
| 315 { |
| 316 struct cleanup *cleanup = make_cleanup (xfree, data); |
| 317 printf_filtered ("exe = '%s'\n", data); |
| 318 do_cleanups (cleanup); |
| 319 } |
| 320 else |
| 321 warning (_("unable to read link '%s'"), filename); |
| 322 } |
| 323 if (mappings_f) |
| 324 { |
| 325 xsnprintf (filename, sizeof filename, "/proc/%ld/maps", pid); |
| 326 data = target_fileio_read_stralloc (filename); |
| 327 if (data) |
| 328 { |
| 329 struct cleanup *cleanup = make_cleanup (xfree, data); |
| 330 char *line; |
| 331 |
| 332 printf_filtered (_("Mapped address spaces:\n\n")); |
| 333 if (gdbarch_addr_bit (gdbarch) == 32) |
| 334 { |
| 335 printf_filtered ("\t%10s %10s %10s %10s %s\n", |
| 336 "Start Addr", |
| 337 " End Addr", |
| 338 " Size", " Offset", "objfile"); |
| 339 } |
| 340 else |
| 341 { |
| 342 printf_filtered (" %18s %18s %10s %10s %s\n", |
| 343 "Start Addr", |
| 344 " End Addr", |
| 345 " Size", " Offset", "objfile"); |
| 346 } |
| 347 |
| 348 for (line = strtok (data, "\n"); line; line = strtok (NULL, "\n")) |
| 349 { |
| 350 ULONGEST addr, endaddr, offset, inode; |
| 351 const char *permissions, *device, *filename; |
| 352 size_t permissions_len, device_len; |
| 353 |
| 354 read_mapping (line, &addr, &endaddr, |
| 355 &permissions, &permissions_len, |
| 356 &offset, &device, &device_len, |
| 357 &inode, &filename); |
| 358 |
| 359 if (gdbarch_addr_bit (gdbarch) == 32) |
| 360 { |
| 361 printf_filtered ("\t%10s %10s %10s %10s %s\n", |
| 362 paddress (gdbarch, addr), |
| 363 paddress (gdbarch, endaddr), |
| 364 hex_string (endaddr - addr), |
| 365 hex_string (offset), |
| 366 *filename? filename : ""); |
| 367 } |
| 368 else |
| 369 { |
| 370 printf_filtered (" %18s %18s %10s %10s %s\n", |
| 371 paddress (gdbarch, addr), |
| 372 paddress (gdbarch, endaddr), |
| 373 hex_string (endaddr - addr), |
| 374 hex_string (offset), |
| 375 *filename? filename : ""); |
| 376 } |
| 377 } |
| 378 |
| 379 do_cleanups (cleanup); |
| 380 } |
| 381 else |
| 382 warning (_("unable to open /proc file '%s'"), filename); |
| 383 } |
| 384 if (status_f) |
| 385 { |
| 386 xsnprintf (filename, sizeof filename, "/proc/%ld/status", pid); |
| 387 data = target_fileio_read_stralloc (filename); |
| 388 if (data) |
| 389 { |
| 390 struct cleanup *cleanup = make_cleanup (xfree, data); |
| 391 puts_filtered (data); |
| 392 do_cleanups (cleanup); |
| 393 } |
| 394 else |
| 395 warning (_("unable to open /proc file '%s'"), filename); |
| 396 } |
| 397 if (stat_f) |
| 398 { |
| 399 xsnprintf (filename, sizeof filename, "/proc/%ld/stat", pid); |
| 400 data = target_fileio_read_stralloc (filename); |
| 401 if (data) |
| 402 { |
| 403 struct cleanup *cleanup = make_cleanup (xfree, data); |
| 404 const char *p = data; |
| 405 |
| 406 printf_filtered (_("Process: %s\n"), |
| 407 pulongest (strtoulst (p, &p, 10))); |
| 408 |
| 409 while (*p && isspace (*p)) |
| 410 p++; |
| 411 if (*p == '(') |
| 412 { |
| 413 const char *ep = strchr (p, ')'); |
| 414 if (ep != NULL) |
| 415 { |
| 416 printf_filtered ("Exec file: %.*s\n", |
| 417 (int) (ep - p - 1), p + 1); |
| 418 p = ep + 1; |
| 419 } |
| 420 } |
| 421 |
| 422 while (*p && isspace (*p)) |
| 423 p++; |
| 424 if (*p) |
| 425 printf_filtered (_("State: %c\n"), *p++); |
| 426 |
| 427 if (*p) |
| 428 printf_filtered (_("Parent process: %s\n"), |
| 429 pulongest (strtoulst (p, &p, 10))); |
| 430 if (*p) |
| 431 printf_filtered (_("Process group: %s\n"), |
| 432 pulongest (strtoulst (p, &p, 10))); |
| 433 if (*p) |
| 434 printf_filtered (_("Session id: %s\n"), |
| 435 pulongest (strtoulst (p, &p, 10))); |
| 436 if (*p) |
| 437 printf_filtered (_("TTY: %s\n"), |
| 438 pulongest (strtoulst (p, &p, 10))); |
| 439 if (*p) |
| 440 printf_filtered (_("TTY owner process group: %s\n"), |
| 441 pulongest (strtoulst (p, &p, 10))); |
| 442 |
| 443 if (*p) |
| 444 printf_filtered (_("Flags: %s\n"), |
| 445 hex_string (strtoulst (p, &p, 10))); |
| 446 if (*p) |
| 447 printf_filtered (_("Minor faults (no memory page): %s\n"), |
| 448 pulongest (strtoulst (p, &p, 10))); |
| 449 if (*p) |
| 450 printf_filtered (_("Minor faults, children: %s\n"), |
| 451 pulongest (strtoulst (p, &p, 10))); |
| 452 if (*p) |
| 453 printf_filtered (_("Major faults (memory page faults): %s\n"), |
| 454 pulongest (strtoulst (p, &p, 10))); |
| 455 if (*p) |
| 456 printf_filtered (_("Major faults, children: %s\n"), |
| 457 pulongest (strtoulst (p, &p, 10))); |
| 458 if (*p) |
| 459 printf_filtered (_("utime: %s\n"), |
| 460 pulongest (strtoulst (p, &p, 10))); |
| 461 if (*p) |
| 462 printf_filtered (_("stime: %s\n"), |
| 463 pulongest (strtoulst (p, &p, 10))); |
| 464 if (*p) |
| 465 printf_filtered (_("utime, children: %s\n"), |
| 466 pulongest (strtoulst (p, &p, 10))); |
| 467 if (*p) |
| 468 printf_filtered (_("stime, children: %s\n"), |
| 469 pulongest (strtoulst (p, &p, 10))); |
| 470 if (*p) |
| 471 printf_filtered (_("jiffies remaining in current " |
| 472 "time slice: %s\n"), |
| 473 pulongest (strtoulst (p, &p, 10))); |
| 474 if (*p) |
| 475 printf_filtered (_("'nice' value: %s\n"), |
| 476 pulongest (strtoulst (p, &p, 10))); |
| 477 if (*p) |
| 478 printf_filtered (_("jiffies until next timeout: %s\n"), |
| 479 pulongest (strtoulst (p, &p, 10))); |
| 480 if (*p) |
| 481 printf_filtered (_("jiffies until next SIGALRM: %s\n"), |
| 482 pulongest (strtoulst (p, &p, 10))); |
| 483 if (*p) |
| 484 printf_filtered (_("start time (jiffies since " |
| 485 "system boot): %s\n"), |
| 486 pulongest (strtoulst (p, &p, 10))); |
| 487 if (*p) |
| 488 printf_filtered (_("Virtual memory size: %s\n"), |
| 489 pulongest (strtoulst (p, &p, 10))); |
| 490 if (*p) |
| 491 printf_filtered (_("Resident set size: %s\n"), |
| 492 pulongest (strtoulst (p, &p, 10))); |
| 493 if (*p) |
| 494 printf_filtered (_("rlim: %s\n"), |
| 495 pulongest (strtoulst (p, &p, 10))); |
| 496 if (*p) |
| 497 printf_filtered (_("Start of text: %s\n"), |
| 498 hex_string (strtoulst (p, &p, 10))); |
| 499 if (*p) |
| 500 printf_filtered (_("End of text: %s\n"), |
| 501 hex_string (strtoulst (p, &p, 10))); |
| 502 if (*p) |
| 503 printf_filtered (_("Start of stack: %s\n"), |
| 504 hex_string (strtoulst (p, &p, 10))); |
| 505 #if 0 /* Don't know how architecture-dependent the rest is... |
| 506 Anyway the signal bitmap info is available from "status". */ |
| 507 if (*p) |
| 508 printf_filtered (_("Kernel stack pointer: %s\n"), |
| 509 hex_string (strtoulst (p, &p, 10))); |
| 510 if (*p) |
| 511 printf_filtered (_("Kernel instr pointer: %s\n"), |
| 512 hex_string (strtoulst (p, &p, 10))); |
| 513 if (*p) |
| 514 printf_filtered (_("Pending signals bitmap: %s\n"), |
| 515 hex_string (strtoulst (p, &p, 10))); |
| 516 if (*p) |
| 517 printf_filtered (_("Blocked signals bitmap: %s\n"), |
| 518 hex_string (strtoulst (p, &p, 10))); |
| 519 if (*p) |
| 520 printf_filtered (_("Ignored signals bitmap: %s\n"), |
| 521 hex_string (strtoulst (p, &p, 10))); |
| 522 if (*p) |
| 523 printf_filtered (_("Catched signals bitmap: %s\n"), |
| 524 hex_string (strtoulst (p, &p, 10))); |
| 525 if (*p) |
| 526 printf_filtered (_("wchan (system call): %s\n"), |
| 527 hex_string (strtoulst (p, &p, 10))); |
| 528 #endif |
| 529 do_cleanups (cleanup); |
| 530 } |
| 531 else |
| 532 warning (_("unable to open /proc file '%s'"), filename); |
| 533 } |
| 534 } |
| 535 |
| 536 /* List memory regions in the inferior for a corefile. */ |
| 537 |
| 538 static int |
| 539 linux_find_memory_regions (struct gdbarch *gdbarch, |
| 540 find_memory_region_ftype func, void *obfd) |
| 541 { |
| 542 char filename[100]; |
| 543 gdb_byte *data; |
| 544 |
| 545 /* We need to know the real target PID to access /proc. */ |
| 546 if (current_inferior ()->fake_pid_p) |
| 547 return 1; |
| 548 |
| 549 xsnprintf (filename, sizeof filename, |
| 550 "/proc/%d/maps", current_inferior ()->pid); |
| 551 data = target_fileio_read_stralloc (filename); |
| 552 if (data) |
| 553 { |
| 554 struct cleanup *cleanup = make_cleanup (xfree, data); |
| 555 char *line; |
| 556 |
| 557 for (line = strtok (data, "\n"); line; line = strtok (NULL, "\n")) |
| 558 { |
| 559 ULONGEST addr, endaddr, offset, inode; |
| 560 const char *permissions, *device, *filename; |
| 561 size_t permissions_len, device_len; |
| 562 int read, write, exec; |
| 563 |
| 564 read_mapping (line, &addr, &endaddr, &permissions, &permissions_len, |
| 565 &offset, &device, &device_len, &inode, &filename); |
| 566 |
| 567 /* Decode permissions. */ |
| 568 read = (memchr (permissions, 'r', permissions_len) != 0); |
| 569 write = (memchr (permissions, 'w', permissions_len) != 0); |
| 570 exec = (memchr (permissions, 'x', permissions_len) != 0); |
| 571 |
| 572 /* Invoke the callback function to create the corefile segment. */ |
| 573 func (addr, endaddr - addr, read, write, exec, obfd); |
| 574 } |
| 575 |
| 576 do_cleanups (cleanup); |
| 577 return 0; |
| 578 } |
| 579 |
| 580 return 1; |
| 581 } |
| 582 |
| 583 /* Determine which signal stopped execution. */ |
| 584 |
| 585 static int |
| 586 find_signalled_thread (struct thread_info *info, void *data) |
| 587 { |
| 588 if (info->suspend.stop_signal != GDB_SIGNAL_0 |
| 589 && ptid_get_pid (info->ptid) == ptid_get_pid (inferior_ptid)) |
| 590 return 1; |
| 591 |
| 592 return 0; |
| 593 } |
| 594 |
| 595 static enum gdb_signal |
| 596 find_stop_signal (void) |
| 597 { |
| 598 struct thread_info *info = |
| 599 iterate_over_threads (find_signalled_thread, NULL); |
| 600 |
| 601 if (info) |
| 602 return info->suspend.stop_signal; |
| 603 else |
| 604 return GDB_SIGNAL_0; |
| 605 } |
| 606 |
| 607 /* Generate corefile notes for SPU contexts. */ |
| 608 |
| 609 static char * |
| 610 linux_spu_make_corefile_notes (bfd *obfd, char *note_data, int *note_size) |
| 611 { |
| 612 static const char *spu_files[] = |
| 613 { |
| 614 "object-id", |
| 615 "mem", |
| 616 "regs", |
| 617 "fpcr", |
| 618 "lslr", |
| 619 "decr", |
| 620 "decr_status", |
| 621 "signal1", |
| 622 "signal1_type", |
| 623 "signal2", |
| 624 "signal2_type", |
| 625 "event_mask", |
| 626 "event_status", |
| 627 "mbox_info", |
| 628 "ibox_info", |
| 629 "wbox_info", |
| 630 "dma_info", |
| 631 "proxydma_info", |
| 632 }; |
| 633 |
| 634 enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch); |
| 635 gdb_byte *spu_ids; |
| 636 LONGEST i, j, size; |
| 637 |
| 638 /* Determine list of SPU ids. */ |
| 639 size = target_read_alloc (¤t_target, TARGET_OBJECT_SPU, |
| 640 NULL, &spu_ids); |
| 641 |
| 642 /* Generate corefile notes for each SPU file. */ |
| 643 for (i = 0; i < size; i += 4) |
| 644 { |
| 645 int fd = extract_unsigned_integer (spu_ids + i, 4, byte_order); |
| 646 |
| 647 for (j = 0; j < sizeof (spu_files) / sizeof (spu_files[0]); j++) |
| 648 { |
| 649 char annex[32], note_name[32]; |
| 650 gdb_byte *spu_data; |
| 651 LONGEST spu_len; |
| 652 |
| 653 xsnprintf (annex, sizeof annex, "%d/%s", fd, spu_files[j]); |
| 654 spu_len = target_read_alloc (¤t_target, TARGET_OBJECT_SPU, |
| 655 annex, &spu_data); |
| 656 if (spu_len > 0) |
| 657 { |
| 658 xsnprintf (note_name, sizeof note_name, "SPU/%s", annex); |
| 659 note_data = elfcore_write_note (obfd, note_data, note_size, |
| 660 note_name, NT_SPU, |
| 661 spu_data, spu_len); |
| 662 xfree (spu_data); |
| 663 |
| 664 if (!note_data) |
| 665 { |
| 666 xfree (spu_ids); |
| 667 return NULL; |
| 668 } |
| 669 } |
| 670 } |
| 671 } |
| 672 |
| 673 if (size > 0) |
| 674 xfree (spu_ids); |
| 675 |
| 676 return note_data; |
| 677 } |
| 678 |
| 679 /* Records the thread's register state for the corefile note |
| 680 section. */ |
| 681 |
| 682 static char * |
| 683 linux_collect_thread_registers (const struct regcache *regcache, |
| 684 ptid_t ptid, bfd *obfd, |
| 685 char *note_data, int *note_size, |
| 686 enum gdb_signal stop_signal) |
| 687 { |
| 688 struct gdbarch *gdbarch = get_regcache_arch (regcache); |
| 689 struct core_regset_section *sect_list; |
| 690 unsigned long lwp; |
| 691 |
| 692 sect_list = gdbarch_core_regset_sections (gdbarch); |
| 693 gdb_assert (sect_list); |
| 694 |
| 695 /* For remote targets the LWP may not be available, so use the TID. */ |
| 696 lwp = ptid_get_lwp (ptid); |
| 697 if (!lwp) |
| 698 lwp = ptid_get_tid (ptid); |
| 699 |
| 700 while (sect_list->sect_name != NULL) |
| 701 { |
| 702 const struct regset *regset; |
| 703 char *buf; |
| 704 |
| 705 regset = gdbarch_regset_from_core_section (gdbarch, |
| 706 sect_list->sect_name, |
| 707 sect_list->size); |
| 708 gdb_assert (regset && regset->collect_regset); |
| 709 |
| 710 buf = xmalloc (sect_list->size); |
| 711 regset->collect_regset (regset, regcache, -1, buf, sect_list->size); |
| 712 |
| 713 /* PRSTATUS still needs to be treated specially. */ |
| 714 if (strcmp (sect_list->sect_name, ".reg") == 0) |
| 715 note_data = (char *) elfcore_write_prstatus |
| 716 (obfd, note_data, note_size, lwp, |
| 717 gdb_signal_to_host (stop_signal), buf); |
| 718 else |
| 719 note_data = (char *) elfcore_write_register_note |
| 720 (obfd, note_data, note_size, |
| 721 sect_list->sect_name, buf, sect_list->size); |
| 722 xfree (buf); |
| 723 sect_list++; |
| 724 |
| 725 if (!note_data) |
| 726 return NULL; |
| 727 } |
| 728 |
| 729 return note_data; |
| 730 } |
| 731 |
| 732 struct linux_corefile_thread_data |
| 733 { |
| 734 struct gdbarch *gdbarch; |
| 735 int pid; |
| 736 bfd *obfd; |
| 737 char *note_data; |
| 738 int *note_size; |
| 739 int num_notes; |
| 740 enum gdb_signal stop_signal; |
| 741 linux_collect_thread_registers_ftype collect; |
| 742 }; |
| 743 |
| 744 /* Called by gdbthread.c once per thread. Records the thread's |
| 745 register state for the corefile note section. */ |
| 746 |
| 747 static int |
| 748 linux_corefile_thread_callback (struct thread_info *info, void *data) |
| 749 { |
| 750 struct linux_corefile_thread_data *args = data; |
| 751 |
| 752 if (ptid_get_pid (info->ptid) == args->pid) |
| 753 { |
| 754 struct cleanup *old_chain; |
| 755 struct regcache *regcache; |
| 756 regcache = get_thread_arch_regcache (info->ptid, args->gdbarch); |
| 757 |
| 758 old_chain = save_inferior_ptid (); |
| 759 inferior_ptid = info->ptid; |
| 760 target_fetch_registers (regcache, -1); |
| 761 do_cleanups (old_chain); |
| 762 |
| 763 args->note_data = args->collect (regcache, info->ptid, args->obfd, |
| 764 args->note_data, args->note_size, |
| 765 args->stop_signal); |
| 766 args->num_notes++; |
| 767 } |
| 768 |
| 769 return !args->note_data; |
| 770 } |
| 771 |
| 772 /* Fills the "to_make_corefile_note" target vector. Builds the note |
| 773 section for a corefile, and returns it in a malloc buffer. */ |
| 774 |
| 775 char * |
| 776 linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size, |
| 777 linux_collect_thread_registers_ftype collect) |
| 778 { |
| 779 struct linux_corefile_thread_data thread_args; |
| 780 char *note_data = NULL; |
| 781 gdb_byte *auxv; |
| 782 int auxv_len; |
| 783 |
| 784 /* Process information. */ |
| 785 if (get_exec_file (0)) |
| 786 { |
| 787 const char *fname = lbasename (get_exec_file (0)); |
| 788 char *psargs = xstrdup (fname); |
| 789 |
| 790 if (get_inferior_args ()) |
| 791 psargs = reconcat (psargs, psargs, " ", get_inferior_args (), |
| 792 (char *) NULL); |
| 793 |
| 794 note_data = elfcore_write_prpsinfo (obfd, note_data, note_size, |
| 795 fname, psargs); |
| 796 xfree (psargs); |
| 797 |
| 798 if (!note_data) |
| 799 return NULL; |
| 800 } |
| 801 |
| 802 /* Thread register information. */ |
| 803 thread_args.gdbarch = gdbarch; |
| 804 thread_args.pid = ptid_get_pid (inferior_ptid); |
| 805 thread_args.obfd = obfd; |
| 806 thread_args.note_data = note_data; |
| 807 thread_args.note_size = note_size; |
| 808 thread_args.num_notes = 0; |
| 809 thread_args.stop_signal = find_stop_signal (); |
| 810 thread_args.collect = collect; |
| 811 iterate_over_threads (linux_corefile_thread_callback, &thread_args); |
| 812 note_data = thread_args.note_data; |
| 813 if (!note_data) |
| 814 return NULL; |
| 815 |
| 816 /* Auxillary vector. */ |
| 817 auxv_len = target_read_alloc (¤t_target, TARGET_OBJECT_AUXV, |
| 818 NULL, &auxv); |
| 819 if (auxv_len > 0) |
| 820 { |
| 821 note_data = elfcore_write_note (obfd, note_data, note_size, |
| 822 "CORE", NT_AUXV, auxv, auxv_len); |
| 823 xfree (auxv); |
| 824 |
| 825 if (!note_data) |
| 826 return NULL; |
| 827 } |
| 828 |
| 829 /* SPU information. */ |
| 830 note_data = linux_spu_make_corefile_notes (obfd, note_data, note_size); |
| 831 if (!note_data) |
| 832 return NULL; |
| 833 |
| 834 make_cleanup (xfree, note_data); |
| 835 return note_data; |
| 836 } |
| 837 |
| 838 static char * |
| 839 linux_make_corefile_notes_1 (struct gdbarch *gdbarch, bfd *obfd, int *note_size) |
| 840 { |
| 841 /* FIXME: uweigand/2011-10-06: Once all GNU/Linux architectures have been |
| 842 converted to gdbarch_core_regset_sections, we no longer need to fall back |
| 843 to the target method at this point. */ |
| 844 |
| 845 if (!gdbarch_core_regset_sections (gdbarch)) |
| 846 return target_make_corefile_notes (obfd, note_size); |
| 847 else |
| 848 return linux_make_corefile_notes (gdbarch, obfd, note_size, |
| 849 linux_collect_thread_registers); |
| 850 } |
| 851 |
199 /* To be called from the various GDB_OSABI_LINUX handlers for the | 852 /* To be called from the various GDB_OSABI_LINUX handlers for the |
200 various GNU/Linux architectures and machine types. */ | 853 various GNU/Linux architectures and machine types. */ |
201 | 854 |
202 void | 855 void |
203 linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | 856 linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) |
204 { | 857 { |
205 set_gdbarch_core_pid_to_str (gdbarch, linux_core_pid_to_str); | 858 set_gdbarch_core_pid_to_str (gdbarch, linux_core_pid_to_str); |
| 859 set_gdbarch_info_proc (gdbarch, linux_info_proc); |
| 860 set_gdbarch_find_memory_regions (gdbarch, linux_find_memory_regions); |
| 861 set_gdbarch_make_corefile_notes (gdbarch, linux_make_corefile_notes_1); |
| 862 set_gdbarch_has_shared_address_space (gdbarch, |
| 863 linux_has_shared_address_space); |
206 } | 864 } |
207 | 865 |
| 866 /* Provide a prototype to silence -Wmissing-prototypes. */ |
| 867 extern initialize_file_ftype _initialize_linux_tdep; |
| 868 |
208 void | 869 void |
209 _initialize_linux_tdep (void) | 870 _initialize_linux_tdep (void) |
210 { | 871 { |
211 linux_gdbarch_data_handle = | 872 linux_gdbarch_data_handle = |
212 gdbarch_data_register_post_init (init_linux_gdbarch_data); | 873 gdbarch_data_register_post_init (init_linux_gdbarch_data); |
213 } | 874 } |
OLD | NEW |