X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=gdb%2Fcorefile.c;h=71f8157134222cf67f3609c3a2e28294ac0f64ff;hb=c76d61da4a65eaadca861bf6c77d579a5cc3f422;hp=c5e4f91a07c909102a89e245260add8d0a870b6a;hpb=6bd6f3b6569945700386847f624dc9e8b7f57450;p=binutils-gdb.git diff --git a/gdb/corefile.c b/gdb/corefile.c index c5e4f91a07c..71f81571342 100644 --- a/gdb/corefile.c +++ b/gdb/corefile.c @@ -1,6 +1,6 @@ /* Core dump and executable file functions above target vector, for GDB. - Copyright (C) 1986-2018 Free Software Foundation, Inc. + Copyright (C) 1986-2022 Free Software Foundation, Inc. This file is part of GDB. @@ -30,8 +30,9 @@ #include "dis-asm.h" #include #include "completer.h" -#include "observer.h" +#include "observable.h" #include "cli/cli-utils.h" +#include "gdbarch.h" /* You can have any number of hooks for `exec_file_command' command to call. If there's only one hook, it is set in exec_file_display @@ -49,29 +50,6 @@ static hook_type *exec_file_extra_hooks; /* Array of additional hooks. */ static int exec_file_hook_count = 0; /* Size of array. */ -/* Binary file diddling handle for the core file. */ - -bfd *core_bfd = NULL; - -/* corelow.c target. It is never NULL after GDB initialization. */ - -struct target_ops *core_target; - - -/* Backward compatability with old way of specifying core files. */ - -void -core_file_command (const char *filename, int from_tty) -{ - dont_repeat (); /* Either way, seems bogus. */ - - gdb_assert (core_target != NULL); - - if (!filename) - (core_target->to_detach) (core_target, from_tty); - else - (core_target->to_open) (filename, from_tty); -} /* If there are two or more functions that wish to hook into @@ -110,8 +88,8 @@ specify_exec_file_hook (void (*hook) (const char *)) } /* Grow the hook array by one and add the new hook to the end. - Yes, it's inefficient to grow it by one each time but since - this is hardly ever called it's not a big deal. */ + Yes, it's inefficient to grow it by one each time but since + this is hardly ever called it's not a big deal. */ exec_file_hook_count++; new_array = (hook_type *) xrealloc (exec_file_extra_hooks, @@ -130,14 +108,16 @@ reopen_exec_file (void) struct stat st; /* Don't do anything if there isn't an exec file. */ - if (exec_bfd == NULL) + if (current_program_space->exec_bfd () == NULL) return; /* If the timestamp of the exec file has changed, reopen it. */ - std::string filename = bfd_get_filename (exec_bfd); + std::string filename = bfd_get_filename (current_program_space->exec_bfd ()); res = stat (filename.c_str (), &st); - if (res == 0 && exec_bfd_mtime && exec_bfd_mtime != st.st_mtime) + if (res == 0 + && current_program_space->ebfd_mtime + && current_program_space->ebfd_mtime != st.st_mtime) exec_file_attach (filename.c_str (), 0); else /* If we accessed the file since last opening it, close it now; @@ -152,28 +132,29 @@ reopen_exec_file (void) void validate_files (void) { - if (exec_bfd && core_bfd) + if (current_program_space->exec_bfd () && core_bfd) { - if (!core_file_matches_executable_p (core_bfd, exec_bfd)) + if (!core_file_matches_executable_p (core_bfd, + current_program_space->exec_bfd ())) warning (_("core file may not match specified executable file.")); - else if (bfd_get_mtime (exec_bfd) > bfd_get_mtime (core_bfd)) + else if (bfd_get_mtime (current_program_space->exec_bfd ()) + > bfd_get_mtime (core_bfd)) warning (_("exec file is newer than core file.")); } } -/* See common/common-inferior.h. */ +/* See gdbsupport/common-inferior.h. */ -char * +const char * get_exec_file (int err) { - if (exec_filename) - return exec_filename; + if (current_program_space->exec_filename != nullptr) + return current_program_space->exec_filename.get (); if (!err) return NULL; error (_("No executable file specified.\n\ Use the \"file\" or \"exec-file\" command.")); - return NULL; } @@ -237,9 +218,8 @@ read_memory_object (enum target_object object, CORE_ADDR memaddr, enum target_xfer_status status; ULONGEST xfered_len; - status = target_xfer_partial (current_target.beneath, - object, NULL, - myaddr + xfered, NULL, + status = target_xfer_partial (current_inferior ()->top_target (), object, + NULL, myaddr + xfered, NULL, memaddr + xfered, len - xfered, &xfered_len); @@ -352,33 +332,6 @@ read_code_unsigned_integer (CORE_ADDR memaddr, int len, return extract_unsigned_integer (buf, len, byte_order); } -void -read_memory_string (CORE_ADDR memaddr, char *buffer, int max_len) -{ - char *cp; - int i; - int cnt; - - cp = buffer; - while (1) - { - if (cp - buffer >= max_len) - { - buffer[max_len - 1] = '\0'; - break; - } - cnt = max_len - (cp - buffer); - if (cnt > 8) - cnt = 8; - read_memory (memaddr + (int) (cp - buffer), (gdb_byte *) cp, cnt); - for (i = 0; i < cnt && *cp; i++, cp++) - ; /* null body */ - - if (i < cnt && !*cp) - break; - } -} - CORE_ADDR read_memory_typed_address (CORE_ADDR addr, struct type *type) { @@ -408,7 +361,7 @@ write_memory_with_notification (CORE_ADDR memaddr, const bfd_byte *myaddr, ssize_t len) { write_memory (memaddr, myaddr, len); - observer_notify_memory_changed (current_inferior (), memaddr, len, myaddr); + gdb::observers::memory_changed.notify (current_inferior (), memaddr, len, myaddr); } /* Store VALUE at ADDR in the inferior as a LEN-byte unsigned @@ -439,32 +392,32 @@ write_memory_signed_integer (CORE_ADDR addr, int len, /* The current default bfd target. Points to storage allocated for gnutarget_string. */ -char *gnutarget; +const char *gnutarget; /* Same thing, except it is "auto" not NULL for the default case. */ -static char *gnutarget_string; +static std::string gnutarget_string; static void show_gnutarget_string (struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value) { - fprintf_filtered (file, - _("The current BFD target is \"%s\".\n"), value); + gdb_printf (file, + _("The current BFD target is \"%s\".\n"), value); } static void set_gnutarget_command (const char *ignore, int from_tty, struct cmd_list_element *c) { - char *gend = gnutarget_string + strlen (gnutarget_string); - - gend = remove_trailing_whitespace (gnutarget_string, gend); - *gend = '\0'; + const char *gend = gnutarget_string.c_str () + gnutarget_string.size (); + gend = remove_trailing_whitespace (gnutarget_string.c_str (), gend); + gnutarget_string + = gnutarget_string.substr (0, gend - gnutarget_string.data ()); - if (strcmp (gnutarget_string, "auto") == 0) + if (gnutarget_string == "auto") gnutarget = NULL; else - gnutarget = gnutarget_string; + gnutarget = gnutarget_string.c_str (); } /* A completion function for "set gnutarget". */ @@ -496,25 +449,25 @@ complete_set_gnutarget (struct cmd_list_element *cmd, void set_gnutarget (const char *newtarget) { - if (gnutarget_string != NULL) - xfree (gnutarget_string); - gnutarget_string = xstrdup (newtarget); + gnutarget_string = newtarget; set_gnutarget_command (NULL, 0, NULL); } +void _initialize_core (); void -_initialize_core (void) +_initialize_core () { - struct cmd_list_element *c; - - c = add_cmd ("core-file", class_files, core_file_command, _("\ + cmd_list_element *core_file_cmd + = add_cmd ("core-file", class_files, core_file_command, _("\ Use FILE as core dump for examining memory and registers.\n\ +Usage: core-file FILE\n\ No arg means have no core file. This command has been superseded by the\n\ `target core' and `detach' commands."), &cmdlist); - set_cmd_completer (c, filename_completer); + set_cmd_completer (core_file_cmd, filename_completer); - c = add_setshow_string_noescape_cmd ("gnutarget", class_files, + set_show_commands set_show_gnutarget + = add_setshow_string_noescape_cmd ("gnutarget", class_files, &gnutarget_string, _("\ Set the current BFD target."), _("\ Show the current BFD target."), _("\ @@ -522,9 +475,9 @@ Use `set gnutarget auto' to specify automatic detection."), set_gnutarget_command, show_gnutarget_string, &setlist, &showlist); - set_cmd_completer (c, complete_set_gnutarget); + set_cmd_completer (set_show_gnutarget.set, complete_set_gnutarget); - add_alias_cmd ("g", "gnutarget", class_files, 1, &setlist); + add_alias_cmd ("g", set_show_gnutarget.set, class_files, 1, &setlist); if (getenv ("GNUTARGET")) set_gnutarget (getenv ("GNUTARGET"));