+/* Handle monitor commands not handled by target-specific handlers. */
+
+static void
+handle_monitor_command (char *mon)
+{
+ if (strcmp (mon, "set debug 1") == 0)
+ {
+ debug_threads = 1;
+ monitor_output ("Debug output enabled.\n");
+ }
+ else if (strcmp (mon, "set debug 0") == 0)
+ {
+ debug_threads = 0;
+ monitor_output ("Debug output disabled.\n");
+ }
+ else if (strcmp (mon, "set debug-hw-points 1") == 0)
+ {
+ debug_hw_points = 1;
+ monitor_output ("H/W point debugging output enabled.\n");
+ }
+ else if (strcmp (mon, "set debug-hw-points 0") == 0)
+ {
+ debug_hw_points = 0;
+ monitor_output ("H/W point debugging output disabled.\n");
+ }
+ else if (strcmp (mon, "set remote-debug 1") == 0)
+ {
+ remote_debug = 1;
+ monitor_output ("Protocol debug output enabled.\n");
+ }
+ else if (strcmp (mon, "set remote-debug 0") == 0)
+ {
+ remote_debug = 0;
+ monitor_output ("Protocol debug output disabled.\n");
+ }
+ else if (strcmp (mon, "help") == 0)
+ monitor_show_help ();
+ else if (strcmp (mon, "exit") == 0)
+ exit_requested = 1;
+ else
+ {
+ monitor_output ("Unknown monitor command.\n\n");
+ monitor_show_help ();
+ write_enn (own_buf);
+ }
+}
+
+static void
+handle_threads_qxfer_proper (struct buffer *buffer)
+{
+ struct inferior_list_entry *thread;
+
+ buffer_grow_str (buffer, "<threads>\n");
+
+ for (thread = all_threads.head; thread; thread = thread->next)
+ {
+ ptid_t ptid = thread_to_gdb_id ((struct thread_info *)thread);
+ char ptid_s[100];
+ int core = -1;
+ char core_s[21];
+
+ write_ptid (ptid_s, ptid);
+
+ if (the_target->core_of_thread)
+ core = (*the_target->core_of_thread) (ptid);
+
+ if (core != -1)
+ {
+ sprintf (core_s, "%d", core);
+ buffer_xml_printf (buffer, "<thread id=\"%s\" core=\"%s\"/>\n",
+ ptid_s, core_s);
+ }
+ else
+ {
+ buffer_xml_printf (buffer, "<thread id=\"%s\"/>\n",
+ ptid_s);
+ }
+ }
+
+ buffer_grow_str0 (buffer, "</threads>\n");
+}
+
+static int
+handle_threads_qxfer (const char *annex,
+ unsigned char *readbuf,
+ CORE_ADDR offset, int length)
+{
+ static char *result = 0;
+ static unsigned int result_length = 0;
+
+ if (annex && strcmp (annex, "") != 0)
+ return 0;
+
+ if (offset == 0)
+ {
+ struct buffer buffer;
+ /* When asked for data at offset 0, generate everything and store into
+ 'result'. Successive reads will be served off 'result'. */
+ if (result)
+ free (result);
+
+ buffer_init (&buffer);
+
+ handle_threads_qxfer_proper (&buffer);
+
+ result = buffer_finish (&buffer);
+ result_length = strlen (result);
+ buffer_free (&buffer);
+ }
+
+ if (offset >= result_length)
+ {
+ /* We're out of data. */
+ free (result);
+ result = NULL;
+ result_length = 0;
+ return 0;
+ }
+
+ if (length > result_length - offset)
+ length = result_length - offset;
+
+ memcpy (readbuf, result + offset, length);
+
+ return length;
+
+}
+
+/* Table used by the crc32 function to calcuate the checksum. */
+
+static unsigned int crc32_table[256] =
+{0, 0};
+
+/* Compute 32 bit CRC from inferior memory.
+
+ On success, return 32 bit CRC.
+ On failure, return (unsigned long long) -1. */
+
+static unsigned long long
+crc32 (CORE_ADDR base, int len, unsigned int crc)
+{
+ if (!crc32_table[1])
+ {
+ /* Initialize the CRC table and the decoding table. */
+ int i, j;
+ unsigned int c;
+
+ for (i = 0; i < 256; i++)
+ {
+ for (c = i << 24, j = 8; j > 0; --j)
+ c = c & 0x80000000 ? (c << 1) ^ 0x04c11db7 : (c << 1);
+ crc32_table[i] = c;
+ }
+ }
+
+ while (len--)
+ {
+ unsigned char byte = 0;
+
+ /* Return failure if memory read fails. */
+ if (read_inferior_memory (base, &byte, 1) != 0)
+ return (unsigned long long) -1;
+
+ crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ byte) & 255];
+ base++;
+ }
+ return (unsigned long long) crc;
+}
+