aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/NEWS8
-rw-r--r--gdb/doc/gdb.texinfo30
-rw-r--r--gdb/testsuite/gdb.server/server-mon.exp46
-rw-r--r--gdbserver/server.cc175
4 files changed, 216 insertions, 43 deletions
diff --git a/gdb/NEWS b/gdb/NEWS
index 94d1fd8..c8166f0 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -48,6 +48,14 @@ show remote thread-options-packet
supported components are: all, threads, event-loop, and remote.
If no components are given then threads is assumed.
+ ** The 'monitor set remote-debug' and 'monitor set event-loop-debug'
+ command have been removed.
+
+ ** The 'monitor set debug 0|1' command has been extended to take a
+ component name, e.g.: 'monitor set debug COMPONENT off|on'.
+ Possible component names are: all, threads, event-loop, and
+ remote.
+
* Python API
** New function gdb.notify_mi(NAME, DATA), that emits custom
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 6d20e4c..15c7199 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -23805,15 +23805,31 @@ Here are the available commands.
@item monitor help
List the available monitor commands.
-@item monitor set debug 0
-@itemx monitor set debug 1
-Disable or enable general debugging messages.
-
-@item monitor set remote-debug 0
-@itemx monitor set remote-debug 1
-Disable or enable specific debugging messages associated with the remote
+@item monitor set debug off
+Disable all internal logging from gdbserver.
+
+@item monitor set debug on
+Enable some general logging from within gdbserver. Currently this is
+equivalent to @kbd{monitor set debug threads on}, but this might
+change in future releases of gdbserver.
+
+@item monitor set debug threads off
+@itemx monitor set debug threads on
+Disable or enable specific logging messages associated with thread
+handling in gdbserver. Currently this category also includes
+additional output not specifically related to thread handling, this
+could change in future releases of gdbserver.
+
+@item monitor set debug remote off
+@itemx monitor set debug remote on
+Disable or enable specific logging messages associated with the remote
protocol (@pxref{Remote Protocol}).
+@item monitor set debug event-loop off
+@itemx monitor set debug event-loop on
+Disable or enable specific logging messages associated with
+gdbserver's event-loop.
+
@item monitor set debug-file filename
@itemx monitor set debug-file
Send any debug output to the given file, or to stderr.
diff --git a/gdb/testsuite/gdb.server/server-mon.exp b/gdb/testsuite/gdb.server/server-mon.exp
index 728cc84..c9bf2e4 100644
--- a/gdb/testsuite/gdb.server/server-mon.exp
+++ b/gdb/testsuite/gdb.server/server-mon.exp
@@ -44,10 +44,48 @@ gdb_test_multiple "monitor help" "monitor help" {
gdb_test "monitor" "Unknown monitor command.*Protocol error.*"
-gdb_test "monitor set debug 1" "Debug output enabled\\."
-gdb_test "monitor set debug 0" "Debug output disabled\\."
-gdb_test "monitor set remote-debug 1" "Protocol debug output enabled\\."
-gdb_test "monitor set remote-debug 0" "Protocol debug output disabled\\."
+gdb_test "monitor set debug 1" "General debug output enabled\\."
+gdb_test "monitor set debug 0" "All debug output disabled\\."
+gdb_test "monitor set debug yeah" \
+ [multi_line \
+ "Missing value for 'set debug yeah' command\\." \
+ "The following monitor commands are supported:" \
+ ".*"]
+gdb_test "monitor set debug on sometimes" \
+ [multi_line \
+ "Junk 'sometimes' found at end of 'set debug on' command\\." \
+ "The following monitor commands are supported:" \
+ ".*"]
+gdb_test "monitor set debug on" "General debug output enabled\\."
+gdb_test "monitor set debug off" "All debug output disabled\\."
+gdb_test "monitor set debug remote 1" "Debug output for 'remote' enabled\\."
+gdb_test "monitor set debug remote 0" "Debug output for 'remote' disabled\\."
+gdb_test "monitor set debug remote on" "Debug output for 'remote' enabled\\."
+gdb_test "monitor set debug remote off" "Debug output for 'remote' disabled\\."
+gdb_test "monitor set debug event-loop 1" "Debug output for 'event-loop' enabled\\."
+gdb_test "monitor set debug event-loop 0" "Debug output for 'event-loop' disabled\\."
+gdb_test "monitor set debug event-loop on" "Debug output for 'event-loop' enabled\\."
+gdb_test "monitor set debug event-loop off" "Debug output for 'event-loop' disabled\\."
+gdb_test "monitor set debug threads 1" "Debug output for 'threads' enabled\\."
+gdb_test "monitor set debug threads 0" "Debug output for 'threads' disabled\\."
+gdb_test "monitor set debug threads on" "Debug output for 'threads' enabled\\."
+gdb_test "monitor set debug threads off" "Debug output for 'threads' disabled\\."
+gdb_test "monitor set debug all 1" "Debug output for 'all' enabled\\."
+gdb_test "monitor set debug all 0" "Debug output for 'all' disabled\\."
+gdb_test "monitor set debug all on" "Debug output for 'all' enabled\\."
+gdb_test "monitor set debug all off" "Debug output for 'all' disabled\\."
+gdb_test "monitor set debug all yeah" \
+ [multi_line \
+ "Invalid value 'yeah' for 'set debug all'\\." \
+ "The following monitor commands are supported:" \
+ ".*"]
+gdb_test "monitor set debug all on sometimes" \
+ [multi_line \
+ "Junk 'sometimes' found at end of 'set debug all on' command\\." \
+ "The following monitor commands are supported:" \
+ ".*"]
+
+
gdb_test "monitor set debug-format all" \
"All extra debug format options enabled\\."
gdb_test "monitor set debug-format none" \
diff --git a/gdbserver/server.cc b/gdbserver/server.cc
index ea5d28c..2ec97d7 100644
--- a/gdbserver/server.cc
+++ b/gdbserver/server.cc
@@ -1143,14 +1143,15 @@ static void
monitor_show_help (void)
{
monitor_output ("The following monitor commands are supported:\n");
- monitor_output (" set debug <0|1>\n");
+ monitor_output (" set debug on\n");
monitor_output (" Enable general debugging messages\n");
+ monitor_output (" set debug off\n");
+ monitor_output (" Disable all debugging messages\n");
+ monitor_output (" set debug COMPONENT <off|on>\n");
+ monitor_output (" Enable debugging messages for COMPONENT, which is\n");
+ monitor_output (" one of: all, threads, remote, event-loop.\n");
monitor_output (" set debug-hw-points <0|1>\n");
monitor_output (" Enable h/w breakpoint/watchpoint debugging messages\n");
- monitor_output (" set remote-debug <0|1>\n");
- monitor_output (" Enable remote protocol debugging messages\n");
- monitor_output (" set event-loop-debug <0|1>\n");
- monitor_output (" Enable event loop debugging messages\n");
monitor_output (" set debug-format option1[,option2,...]\n");
monitor_output (" Add additional information to debugging messages\n");
monitor_output (" Options: all, none, timestamp\n");
@@ -1575,50 +1576,160 @@ parse_debug_options (const char *options)
}
}
-/* Handle monitor commands not handled by target-specific handlers. */
+/* Called from the 'monitor' command handler, to handle general 'set debug'
+ monitor commands with one of the formats:
-static void
-handle_monitor_command (char *mon, char *own_buf)
+ set debug COMPONENT VALUE
+ set debug VALUE
+
+ In both of these command formats VALUE can be 'on', 'off', '1', or '0'
+ with 1/0 being equivalent to on/off respectively.
+
+ In the no-COMPONENT version of the command, if VALUE is 'on' (or '1')
+ then the component 'threads' is assumed, this is for backward
+ compatibility, but maybe in the future we might find a better "default"
+ set of debug flags to enable.
+
+ In the no-COMPONENT version of the command, if VALUE is 'off' (or '0')
+ then all debugging is turned off.
+
+ Otherwise, COMPONENT must be one of the known debug components, and that
+ component is either enabled or disabled as appropriate.
+
+ The string MON contains either 'COMPONENT VALUE' or just the 'VALUE' for
+ the second command format, the 'set debug ' has been stripped off
+ already.
+
+ Return a string containing an error message if something goes wrong,
+ this error can be returned as part of the monitor command output. If
+ everything goes correctly then the debug global will have been updated,
+ and an empty string is returned. */
+
+static std::string
+handle_general_monitor_debug (const char *mon)
{
- if (strcmp (mon, "set debug 1") == 0)
+ mon = skip_spaces (mon);
+
+ if (*mon == '\0')
+ return "No debug component name found.\n";
+
+ /* Find the first word within MON. This is either the component name,
+ or the value if no component has been given. */
+ const char *end = skip_to_space (mon);
+ std::string component (mon, end - mon);
+ if (component.find (',') != component.npos || component[0] == '-'
+ || component[0] == '+')
+ return "Invalid character found in debug component name.\n";
+
+ /* In ACTION_STR we create a string that will be passed to the
+ parse_debug_options string. This will be either '+COMPONENT' or
+ '-COMPONENT' depending on whether we want to enable or disable
+ COMPONENT. */
+ std::string action_str;
+
+ /* If parse_debug_options succeeds, then MSG will be returned to the user
+ as the output of the monitor command. */
+ std::string msg;
+
+ /* Check for 'set debug off', this disables all debug output. */
+ if (component == "0" || component == "off")
{
- debug_threads = true;
- monitor_output ("Debug output enabled.\n");
+ if (*skip_spaces (end) != '\0')
+ return string_printf
+ ("Junk '%s' found at end of 'set debug %s' command.\n",
+ skip_spaces (end), std::string (mon, end - mon).c_str ());
+
+ action_str = "-all";
+ msg = "All debug output disabled.\n";
}
- else if (strcmp (mon, "set debug 0") == 0)
+ /* Check for 'set debug on', this disables a general set of debug. */
+ else if (component == "1" || component == "on")
{
- debug_threads = false;
- monitor_output ("Debug output disabled.\n");
+ if (*skip_spaces (end) != '\0')
+ return string_printf
+ ("Junk '%s' found at end of 'set debug %s' command.\n",
+ skip_spaces (end), std::string (mon, end - mon).c_str ());
+
+ action_str = "+threads";
+ msg = "General debug output enabled.\n";
}
- else if (strcmp (mon, "set debug-hw-points 1") == 0)
+ /* Otherwise we should have 'set debug COMPONENT VALUE'. Extract the two
+ parts and validate. */
+ else
{
- show_debug_regs = 1;
- monitor_output ("H/W point debugging output enabled.\n");
+ /* Figure out the value the user passed. */
+ const char *value_start = skip_spaces (end);
+ if (*value_start == '\0')
+ return string_printf ("Missing value for 'set debug %s' command.\n",
+ mon);
+
+ const char *after_value = skip_to_space (value_start);
+ if (*skip_spaces (after_value) != '\0')
+ return string_printf
+ ("Junk '%s' found at end of 'set debug %s' command.\n",
+ skip_spaces (after_value),
+ std::string (mon, after_value - mon).c_str ());
+
+ std::string value (value_start, after_value - value_start);
+
+ /* Check VALUE to see if we are enabling, or disabling. */
+ bool enable;
+ if (value == "0" || value == "off")
+ enable = false;
+ else if (value == "1" || value == "on")
+ enable = true;
+ else
+ return string_printf ("Invalid value '%s' for 'set debug %s'.\n",
+ value.c_str (),
+ std::string (mon, end - mon).c_str ());
+
+ action_str = std::string (enable ? "+" : "-") + component;
+ msg = string_printf ("Debug output for '%s' %s.\n", component.c_str (),
+ enable ? "enabled" : "disabled");
}
- else if (strcmp (mon, "set debug-hw-points 0") == 0)
+
+ gdb_assert (!msg.empty ());
+ gdb_assert (!action_str.empty ());
+
+ try
{
- show_debug_regs = 0;
- monitor_output ("H/W point debugging output disabled.\n");
+ parse_debug_options (action_str.c_str ());
+ monitor_output (msg.c_str ());
}
- else if (strcmp (mon, "set remote-debug 1") == 0)
+ catch (const gdb_exception_error &exception)
{
- remote_debug = true;
- monitor_output ("Protocol debug output enabled.\n");
+ return string_printf ("Error: %s\n", exception.what ());
}
- else if (strcmp (mon, "set remote-debug 0") == 0)
+
+ return {};
+}
+
+/* Handle monitor commands not handled by target-specific handlers. */
+
+static void
+handle_monitor_command (char *mon, char *own_buf)
+{
+ if (startswith (mon, "set debug "))
{
- remote_debug = false;
- monitor_output ("Protocol debug output disabled.\n");
+ std::string error_msg
+ = handle_general_monitor_debug (mon + sizeof ("set debug ") - 1);
+
+ if (!error_msg.empty ())
+ {
+ monitor_output (error_msg.c_str ());
+ monitor_show_help ();
+ write_enn (own_buf);
+ }
}
- else if (strcmp (mon, "set event-loop-debug 1") == 0)
+ else if (strcmp (mon, "set debug-hw-points 1") == 0)
{
- debug_event_loop = debug_event_loop_kind::ALL;
- monitor_output ("Event loop debug output enabled.\n");
+ show_debug_regs = 1;
+ monitor_output ("H/W point debugging output enabled.\n");
}
- else if (strcmp (mon, "set event-loop-debug 0") == 0)
+ else if (strcmp (mon, "set debug-hw-points 0") == 0)
{
- debug_event_loop = debug_event_loop_kind::OFF;
- monitor_output ("Event loop debug output disabled.\n");
+ show_debug_regs = 0;
+ monitor_output ("H/W point debugging output disabled.\n");
}
else if (startswith (mon, "set debug-format "))
{