+/* Opaque data for load_progress for a single section. */
+struct load_progress_section_data {
+ struct load_progress_data *cumulative;
+
+ /* Per-section data. */
+ const char *section_name;
+ ULONGEST section_sent;
+ ULONGEST section_size;
+ CORE_ADDR lma;
+ gdb_byte *buffer;
+};
+
+/* Target write callback routine for progress reporting. */
+
+static void
+load_progress (ULONGEST bytes, void *untyped_arg)
+{
+ struct load_progress_section_data *args = untyped_arg;
+ struct load_progress_data *totals;
+
+ if (args == NULL)
+ /* Writing padding data. No easy way to get at the cumulative
+ stats, so just ignore this. */
+ return;
+
+ totals = args->cumulative;
+
+ if (bytes == 0 && args->section_sent == 0)
+ {
+ /* The write is just starting. Let the user know we've started
+ this section. */
+ ui_out_message (uiout, 0, "Loading section %s, size 0x%s lma 0x%s\n",
+ args->section_name, paddr_nz (args->section_size),
+ paddr_nz (args->lma));
+ return;
+ }
+
+ if (validate_download)
+ {
+ /* Broken memories and broken monitors manifest themselves here
+ when bring new computers to life. This doubles already slow
+ downloads. */
+ /* NOTE: cagney/1999-10-18: A more efficient implementation
+ might add a verify_memory() method to the target vector and
+ then use that. remote.c could implement that method using
+ the ``qCRC'' packet. */
+ gdb_byte *check = xmalloc (bytes);
+ struct cleanup *verify_cleanups = make_cleanup (xfree, check);
+
+ if (target_read_memory (args->lma, check, bytes) != 0)
+ error (_("Download verify read failed at 0x%s"),
+ paddr (args->lma));
+ if (memcmp (args->buffer, check, bytes) != 0)
+ error (_("Download verify compare failed at 0x%s"),
+ paddr (args->lma));
+ do_cleanups (verify_cleanups);
+ }
+ totals->data_count += bytes;
+ args->lma += bytes;
+ args->buffer += bytes;
+ totals->write_count += 1;
+ args->section_sent += bytes;
+ if (quit_flag
+ || (deprecated_ui_load_progress_hook != NULL
+ && deprecated_ui_load_progress_hook (args->section_name,
+ args->section_sent)))
+ error (_("Canceled the download"));
+
+ if (deprecated_show_load_progress != NULL)
+ deprecated_show_load_progress (args->section_name,
+ args->section_sent,
+ args->section_size,
+ totals->data_count,
+ totals->total_size);
+}
+