gdbserver: introduce remote_debug_printf
Add remote_debug_printf, and use it for all debug messages controlled by remote_debug. Change remote_debug to be a bool, which is trivial in this case. Change-Id: I90de13cb892faec3830047b571661822b126d6e8
This commit is contained in:
parent
c058728c31
commit
91f94053dd
@ -20,7 +20,7 @@
|
||||
#include <chrono>
|
||||
|
||||
#if !defined (IN_PROCESS_AGENT)
|
||||
int remote_debug = 0;
|
||||
bool remote_debug = false;
|
||||
#endif
|
||||
|
||||
/* Output file for debugging. Default to standard error. */
|
||||
|
@ -20,7 +20,13 @@
|
||||
#define GDBSERVER_DEBUG_H
|
||||
|
||||
#if !defined (IN_PROCESS_AGENT)
|
||||
extern int remote_debug;
|
||||
extern bool remote_debug;
|
||||
|
||||
/* Print a "remote" debug statement. */
|
||||
|
||||
#define remote_debug_printf(fmt, ...) \
|
||||
debug_prefixed_printf_cond (remote_debug, \
|
||||
"remote", fmt, ##__VA_ARGS__)
|
||||
|
||||
/* Switch all debug output to DEBUG_FILE. If DEBUG_FILE is nullptr or an
|
||||
empty string, or if the file cannot be opened, then debug output is sent to
|
||||
|
@ -102,9 +102,8 @@ handle_notif_ack (char *own_buf, int packet_len)
|
||||
struct notif_event *head = np->queue.front ();
|
||||
np->queue.pop_front ();
|
||||
|
||||
if (remote_debug)
|
||||
debug_printf ("%s: acking %d\n", np->ack_name,
|
||||
(int) np->queue.size ());
|
||||
remote_debug_printf ("%s: acking %d", np->ack_name,
|
||||
(int) np->queue.size ());
|
||||
|
||||
delete head;
|
||||
}
|
||||
@ -122,9 +121,8 @@ notif_event_enque (struct notif_server *notif,
|
||||
{
|
||||
notif->queue.push_back (event);
|
||||
|
||||
if (remote_debug)
|
||||
debug_printf ("pending events: %s %d\n", notif->notif_name,
|
||||
(int) notif->queue.size ());
|
||||
remote_debug_printf ("pending events: %s %d", notif->notif_name,
|
||||
(int) notif->queue.size ());
|
||||
|
||||
}
|
||||
|
||||
|
@ -670,22 +670,15 @@ putpkt_binary_1 (char *buf, int cnt, int is_notif)
|
||||
if (cs.noack_mode || is_notif)
|
||||
{
|
||||
/* Don't expect an ack then. */
|
||||
if (remote_debug)
|
||||
{
|
||||
if (is_notif)
|
||||
debug_printf ("putpkt (\"%s\"); [notif]\n", buf2);
|
||||
else
|
||||
debug_printf ("putpkt (\"%s\"); [noack mode]\n", buf2);
|
||||
debug_flush ();
|
||||
}
|
||||
if (is_notif)
|
||||
remote_debug_printf ("putpkt (\"%s\"); [notif]", buf2);
|
||||
else
|
||||
remote_debug_printf ("putpkt (\"%s\"); [noack mode]", buf2);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (remote_debug)
|
||||
{
|
||||
debug_printf ("putpkt (\"%s\"); [looking for ack]\n", buf2);
|
||||
debug_flush ();
|
||||
}
|
||||
remote_debug_printf ("putpkt (\"%s\"); [looking for ack]", buf2);
|
||||
|
||||
cc = readchar ();
|
||||
|
||||
@ -695,11 +688,7 @@ putpkt_binary_1 (char *buf, int cnt, int is_notif)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (remote_debug)
|
||||
{
|
||||
debug_printf ("[received '%c' (0x%x)]\n", cc, cc);
|
||||
debug_flush ();
|
||||
}
|
||||
remote_debug_printf ("[received '%c' (0x%x)]", cc, cc);
|
||||
|
||||
/* Check for an input interrupt while we're here. */
|
||||
if (cc == '\003' && current_thread != NULL)
|
||||
@ -868,8 +857,7 @@ readchar (void)
|
||||
{
|
||||
if (readchar_bufcnt == 0)
|
||||
{
|
||||
if (remote_debug)
|
||||
debug_printf ("readchar: Got EOF\n");
|
||||
remote_debug_printf ("readchar: Got EOF");
|
||||
}
|
||||
else
|
||||
perror ("readchar");
|
||||
@ -950,11 +938,8 @@ getpkt (char *buf)
|
||||
|
||||
if (c == '$')
|
||||
break;
|
||||
if (remote_debug)
|
||||
{
|
||||
debug_printf ("[getpkt: discarding char '%c']\n", c);
|
||||
debug_flush ();
|
||||
}
|
||||
|
||||
remote_debug_printf ("[getpkt: discarding char '%c']", c);
|
||||
|
||||
if (c < 0)
|
||||
return -1;
|
||||
@ -997,29 +982,15 @@ getpkt (char *buf)
|
||||
|
||||
if (!cs.noack_mode)
|
||||
{
|
||||
if (remote_debug)
|
||||
{
|
||||
debug_printf ("getpkt (\"%s\"); [sending ack] \n", buf);
|
||||
debug_flush ();
|
||||
}
|
||||
remote_debug_printf ("getpkt (\"%s\"); [sending ack]", buf);
|
||||
|
||||
if (write_prim ("+", 1) != 1)
|
||||
return -1;
|
||||
|
||||
if (remote_debug)
|
||||
{
|
||||
debug_printf ("[sent ack]\n");
|
||||
debug_flush ();
|
||||
}
|
||||
remote_debug_printf ("[sent ack]");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (remote_debug)
|
||||
{
|
||||
debug_printf ("getpkt (\"%s\"); [no ack sent] \n", buf);
|
||||
debug_flush ();
|
||||
}
|
||||
}
|
||||
remote_debug_printf ("getpkt (\"%s\"); [no ack sent]", buf);
|
||||
|
||||
/* The readchar above may have already read a '\003' out of the socket
|
||||
and moved it to the local buffer. For example, when GDB sends
|
||||
|
@ -736,13 +736,9 @@ handle_general_set (char *own_buf)
|
||||
std::string final_var = hex2str (p);
|
||||
std::string var_name, var_value;
|
||||
|
||||
if (remote_debug)
|
||||
{
|
||||
debug_printf (_("[QEnvironmentHexEncoded received '%s']\n"), p);
|
||||
debug_printf (_("[Environment variable to be set: '%s']\n"),
|
||||
final_var.c_str ());
|
||||
debug_flush ();
|
||||
}
|
||||
remote_debug_printf ("[QEnvironmentHexEncoded received '%s']", p);
|
||||
remote_debug_printf ("[Environment variable to be set: '%s']",
|
||||
final_var.c_str ());
|
||||
|
||||
size_t pos = final_var.find ('=');
|
||||
if (pos == std::string::npos)
|
||||
@ -767,13 +763,9 @@ handle_general_set (char *own_buf)
|
||||
const char *p = own_buf + sizeof ("QEnvironmentUnset:") - 1;
|
||||
std::string varname = hex2str (p);
|
||||
|
||||
if (remote_debug)
|
||||
{
|
||||
debug_printf (_("[QEnvironmentUnset received '%s']\n"), p);
|
||||
debug_printf (_("[Environment variable to be unset: '%s']\n"),
|
||||
varname.c_str ());
|
||||
debug_flush ();
|
||||
}
|
||||
remote_debug_printf ("[QEnvironmentUnset received '%s']", p);
|
||||
remote_debug_printf ("[Environment variable to be unset: '%s']",
|
||||
varname.c_str ());
|
||||
|
||||
our_environ.unset (varname.c_str ());
|
||||
|
||||
@ -783,11 +775,7 @@ handle_general_set (char *own_buf)
|
||||
|
||||
if (strcmp (own_buf, "QStartNoAckMode") == 0)
|
||||
{
|
||||
if (remote_debug)
|
||||
{
|
||||
debug_printf ("[noack mode enabled]\n");
|
||||
debug_flush ();
|
||||
}
|
||||
remote_debug_printf ("[noack mode enabled]");
|
||||
|
||||
cs.noack_mode = 1;
|
||||
write_ok (own_buf);
|
||||
@ -824,8 +812,7 @@ handle_general_set (char *own_buf)
|
||||
|
||||
non_stop = (req != 0);
|
||||
|
||||
if (remote_debug)
|
||||
debug_printf ("[%s mode enabled]\n", req_str);
|
||||
remote_debug_printf ("[%s mode enabled]", req_str);
|
||||
|
||||
write_ok (own_buf);
|
||||
return;
|
||||
@ -839,12 +826,9 @@ handle_general_set (char *own_buf)
|
||||
unpack_varlen_hex (packet, &setting);
|
||||
cs.disable_randomization = setting;
|
||||
|
||||
if (remote_debug)
|
||||
{
|
||||
debug_printf (cs.disable_randomization
|
||||
? "[address space randomization disabled]\n"
|
||||
: "[address space randomization enabled]\n");
|
||||
}
|
||||
remote_debug_printf (cs.disable_randomization
|
||||
? "[address space randomization disabled]"
|
||||
: "[address space randomization enabled]");
|
||||
|
||||
write_ok (own_buf);
|
||||
return;
|
||||
@ -872,8 +856,7 @@ handle_general_set (char *own_buf)
|
||||
|
||||
/* Update the flag. */
|
||||
use_agent = req;
|
||||
if (remote_debug)
|
||||
debug_printf ("[%s agent]\n", req ? "Enable" : "Disable");
|
||||
remote_debug_printf ("[%s agent]", req ? "Enable" : "Disable");
|
||||
write_ok (own_buf);
|
||||
return;
|
||||
}
|
||||
@ -905,12 +888,8 @@ handle_general_set (char *own_buf)
|
||||
|
||||
cs.report_thread_events = (req == TRIBOOL_TRUE);
|
||||
|
||||
if (remote_debug)
|
||||
{
|
||||
const char *req_str = cs.report_thread_events ? "enabled" : "disabled";
|
||||
|
||||
debug_printf ("[thread events are now %s]\n", req_str);
|
||||
}
|
||||
remote_debug_printf ("[thread events are now %s]\n",
|
||||
cs.report_thread_events ? "enabled" : "disabled");
|
||||
|
||||
write_ok (own_buf);
|
||||
return;
|
||||
@ -933,9 +912,8 @@ handle_general_set (char *own_buf)
|
||||
return;
|
||||
}
|
||||
|
||||
if (remote_debug)
|
||||
debug_printf (_("[Inferior will %s started with shell]"),
|
||||
startup_with_shell ? "be" : "not be");
|
||||
remote_debug_printf ("[Inferior will %s started with shell]",
|
||||
startup_with_shell ? "be" : "not be");
|
||||
|
||||
write_ok (own_buf);
|
||||
return;
|
||||
@ -949,9 +927,8 @@ handle_general_set (char *own_buf)
|
||||
{
|
||||
std::string path = hex2str (p);
|
||||
|
||||
if (remote_debug)
|
||||
debug_printf (_("[Set the inferior's current directory to %s]\n"),
|
||||
path.c_str ());
|
||||
remote_debug_printf ("[Set the inferior's current directory to %s]",
|
||||
path.c_str ());
|
||||
|
||||
set_inferior_cwd (std::move (path));
|
||||
}
|
||||
@ -961,9 +938,8 @@ handle_general_set (char *own_buf)
|
||||
previously set cwd for the inferior. */
|
||||
set_inferior_cwd ("");
|
||||
|
||||
if (remote_debug)
|
||||
debug_printf (_("\
|
||||
[Unset the inferior's current directory; will use gdbserver's cwd]\n"));
|
||||
remote_debug_printf ("[Unset the inferior's current directory; will "
|
||||
"use gdbserver's cwd]");
|
||||
}
|
||||
write_ok (own_buf);
|
||||
|
||||
@ -1399,12 +1375,12 @@ handle_monitor_command (char *mon, char *own_buf)
|
||||
}
|
||||
else if (strcmp (mon, "set remote-debug 1") == 0)
|
||||
{
|
||||
remote_debug = 1;
|
||||
remote_debug = true;
|
||||
monitor_output ("Protocol debug output enabled.\n");
|
||||
}
|
||||
else if (strcmp (mon, "set remote-debug 0") == 0)
|
||||
{
|
||||
remote_debug = 0;
|
||||
remote_debug = false;
|
||||
monitor_output ("Protocol debug output disabled.\n");
|
||||
}
|
||||
else if (strcmp (mon, "set event-loop-debug 1") == 0)
|
||||
@ -3827,7 +3803,7 @@ captured_main (int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
else if (strcmp (*next_arg, "--remote-debug") == 0)
|
||||
remote_debug = 1;
|
||||
remote_debug = true;
|
||||
else if (strcmp (*next_arg, "--event-loop-debug") == 0)
|
||||
debug_event_loop = debug_event_loop_kind::ALL;
|
||||
else if (startswith (*next_arg, "--debug-file="))
|
||||
|
Loading…
x
Reference in New Issue
Block a user