aboutsummaryrefslogtreecommitdiff
path: root/gdbserver
diff options
context:
space:
mode:
authorAlexandra Hájková <ahajkova@redhat.com>2024-10-16 13:25:41 +0200
committerAlexandra Hájková <ahajkova@redhat.com>2024-10-21 16:38:18 +0200
commit0cb7f3a837c238cc94f6868eb0344ded34942af4 (patch)
treea9b499e2be08e6bd98ef654aad62c7baf282a3dc /gdbserver
parent32ffcd0737a703398646f7e0b62bd5de348319e1 (diff)
downloadgdb-0cb7f3a837c238cc94f6868eb0344ded34942af4.zip
gdb-0cb7f3a837c238cc94f6868eb0344ded34942af4.tar.gz
gdb-0cb7f3a837c238cc94f6868eb0344ded34942af4.tar.bz2
gdbreplay: Add --debug-logging option
As gdbreplay communicates with GDB, it outputs all the remote protocol communication it reads from the remotelogfile to stderr. This patch disables this behavior by default but adds the new --debug-logging option which turns printing the packets to stderr on again. The motivation for this change is to make it possible to use gdbreplay with TCL tests. Printing the whole remotelog file out seems to overflow the expect cache wich causes gdbreplay to not to get the packet its expects and results in going out of sync with GDB. Other motivation is making communication between GDB and gdbreplay faster as printing bigger remotelogfile takes considerable amount of time. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdbserver')
-rw-r--r--gdbserver/README11
-rw-r--r--gdbserver/gdbreplay.cc73
2 files changed, 61 insertions, 23 deletions
diff --git a/gdbserver/README b/gdbserver/README
index 5b47510..e7e99ec 100644
--- a/gdbserver/README
+++ b/gdbserver/README
@@ -125,8 +125,9 @@ Then start GDB (preferably in a different screen or window) and use the
Repeat the same sequence of user commands to GDB that you gave in the
original debug session. GDB should not be able to tell that it is talking
-to GDBreplay rather than a real target, all other things being equal. Note
-that GDBreplay echos the command lines to stderr, as well as the contents of
-the packets it sends and receives. The last command echoed by GDBreplay is
-the next command that needs to be typed to GDB to continue the session in
-sync with the original session.
+to GDBreplay rather than a real target, all other things being equal.
+
+As GDBreplay communicates with GDB, it outputs only the commands
+it expects from GDB. The --debug-logging option turns printing the
+remotelogfile to stderr on. GDBreplay then echos the command lines
+to stderr, as well as the contents of the packets it sends and receives.
diff --git a/gdbserver/gdbreplay.cc b/gdbserver/gdbreplay.cc
index 7ef52b8..a2c77ce 100644
--- a/gdbserver/gdbreplay.cc
+++ b/gdbserver/gdbreplay.cc
@@ -68,6 +68,9 @@ typedef int socklen_t;
static int remote_desc_in;
static int remote_desc_out;
+/* When true all packets are printed to stderr as they are handled by
+ gdbreplay. */
+bool debug_logging = false;
static void
sync_error (FILE *fp, const char *desc, int expect, int got)
@@ -261,13 +264,13 @@ remote_open (const char *name)
}
static int
-logchar (FILE *fp)
+logchar (FILE *fp, bool print)
{
int ch;
int ch2;
ch = fgetc (fp);
- if (ch != '\r')
+ if (ch != '\r' && (print || debug_logging))
{
fputc (ch, stderr);
fflush (stderr);
@@ -284,16 +287,22 @@ logchar (FILE *fp)
ungetc (ch, fp);
ch = '\r';
}
- fputc (ch == EOL ? '\n' : '\r', stderr);
- fflush (stderr);
+ if (print || debug_logging)
+ {
+ fputc (ch == EOL ? '\n' : '\r', stderr);
+ fflush (stderr);
+ }
break;
case '\n':
ch = EOL;
break;
case '\\':
ch = fgetc (fp);
- fputc (ch, stderr);
- fflush (stderr);
+ if (print || debug_logging)
+ {
+ fputc (ch, stderr);
+ fflush (stderr);
+ }
switch (ch)
{
case '\\':
@@ -318,14 +327,28 @@ logchar (FILE *fp)
break;
case 'x':
ch2 = fgetc (fp);
- fputc (ch2, stderr);
- fflush (stderr);
+ if (print || debug_logging)
+ {
+ fputc (ch2, stderr);
+ fflush (stderr);
+ }
ch = fromhex (ch2) << 4;
ch2 = fgetc (fp);
- fputc (ch2, stderr);
- fflush (stderr);
+ if (print || debug_logging)
+ {
+ fputc (ch2, stderr);
+ fflush (stderr);
+ }
ch |= fromhex (ch2);
break;
+ case 'c':
+ fputc (ch, stderr);
+ fflush (stderr);
+ break;
+ case 'E':
+ fputc (ch, stderr);
+ fflush (stderr);
+ break;
default:
/* Treat any other char as just itself */
break;
@@ -356,14 +379,14 @@ expect (FILE *fp)
int fromlog;
int fromgdb;
- if ((fromlog = logchar (fp)) != ' ')
+ if ((fromlog = logchar (fp, false)) != ' ')
{
sync_error (fp, "Sync error during gdb read of leading blank", ' ',
fromlog);
}
do
{
- fromlog = logchar (fp);
+ fromlog = logchar (fp, false);
if (fromlog == EOL)
break;
fromgdb = gdbchar (remote_desc_in);
@@ -388,12 +411,12 @@ play (FILE *fp)
int fromlog;
char ch;
- if ((fromlog = logchar (fp)) != ' ')
+ if ((fromlog = logchar (fp, false)) != ' ')
{
sync_error (fp, "Sync error skipping blank during write to gdb", ' ',
fromlog);
}
- while ((fromlog = logchar (fp)) != EOL)
+ while ((fromlog = logchar (fp, false)) != EOL)
{
ch = fromlog;
if (write (remote_desc_out, &ch, 1) != 1)
@@ -428,11 +451,12 @@ captured_main (int argc, char *argv[])
{
FILE *fp;
int ch, optc;
- enum opts { OPT_VERSION = 1, OPT_HELP };
+ enum opts { OPT_VERSION = 1, OPT_HELP, OPT_LOGGING };
static struct option longopts[] =
{
{"version", no_argument, nullptr, OPT_VERSION},
{"help", no_argument, nullptr, OPT_HELP},
+ {"debug-logging", no_argument, nullptr, OPT_LOGGING},
{nullptr, no_argument, nullptr, 0}
};
@@ -446,6 +470,9 @@ captured_main (int argc, char *argv[])
case OPT_HELP:
gdbreplay_usage (stdout);
exit (0);
+ case OPT_LOGGING:
+ debug_logging = true;
+ break;
}
}
@@ -460,7 +487,7 @@ captured_main (int argc, char *argv[])
perror_with_name (argv[optind]);
}
remote_open (argv[optind + 1]);
- while ((ch = logchar (fp)) != EOF)
+ while ((ch = logchar (fp, false)) != EOF)
{
switch (ch)
{
@@ -473,8 +500,18 @@ captured_main (int argc, char *argv[])
play (fp);
break;
case 'c':
- /* Command executed by gdb */
- while ((ch = logchar (fp)) != EOL);
+ /* We want to always print the command executed by GDB. */
+ if (!debug_logging)
+ {
+ fprintf (stderr, "\n");
+ fprintf (stderr, "Command expected from GDB:\n");
+ }
+ while ((ch = logchar (fp, true)) != EOL);
+ break;
+ case 'E':
+ if (!debug_logging)
+ fprintf (stderr, "E");
+ while ((ch = logchar (fp, true)) != EOL);
break;
}
}