vgdb --multi: fix various typos, indentation and such

Remove --launched-with-multi from --help-debug output since it is not
a real user option. Do add a comment in m_main.c explaining the
internal usage.

Add a top-level comment describing the three usages of vgdb.

Fix comment description of decode_hexstring, create_packet,
split_hexdecode.

Consistently use 3 space indention in send_packet and receive_packet
and next_delim_string and split_hexdecode, count_delims,
do_multi_mode.

Fix return type of count_delims to size_t.

Add a note in coregrind/m_gdbserver/server.c to sync qSupported
replies with coregrind/vgdb.c.

Use vgdb (all lowercase) and GDB (all caps) consistently in the
manual.
This commit is contained in:
Alexandra Hájková 2023-04-20 14:17:29 +02:00 committed by Mark Wielaard
parent 0ead4c39f0
commit 56ccb1e36c
6 changed files with 144 additions and 140 deletions

View File

@ -1105,7 +1105,7 @@ void handle_query (char *arg_own_buf, int *new_packet_len_p)
return;
}
/* Protocol features query. */
/* Protocol features query. Keep this in sync with coregind/vgdb.c. */
if (strncmp ("qSupported", arg_own_buf, 10) == 0
&& (arg_own_buf[10] == ':' || arg_own_buf[10] == '\0')) {
VG_(sprintf) (arg_own_buf, "PacketSize=%x", (UInt)PBUFSIZ - 1);

View File

@ -279,8 +279,6 @@ static void usage_NORETURN ( int need_help )
" --progress-interval=<number> report progress every <number>\n"
" CPU seconds [0, meaning disabled]\n"
" --command-line-only=no|yes only use command line options [no]\n"
" --launched-with-multi=no|yes valgrind launched in vgdb multi mode [no]\n"
"\n"
" Vex options for all Valgrind tools:\n"
" --vex-iropt-verbosity=<0..9> [0]\n"
" --vex-iropt-level=<0..2> [2]\n"
@ -563,6 +561,8 @@ static void process_option (Clo_Mode mode,
}
else if VG_INT_CLOM (cloPD, arg, "--vgdb-poll", VG_(clo_vgdb_poll)) {}
else if VG_INT_CLOM (cloPD, arg, "--vgdb-error", VG_(clo_vgdb_error)) {}
/* --launched-with-multi is an internal option used by vgdb to suppress
some output that valgrind normally shows when using --vgdb-error. */
else if VG_BOOL_CLO (arg, "--launched-with-multi",
VG_(clo_launched_with_multi)) {}
else if VG_USET_CLOM (cloPD, arg, "--vgdb-stop-at",

View File

@ -900,8 +900,7 @@ int tohex (int nib)
return 'a' + nib - 10;
}
/* Returns an allocated hex-decoded string from the buf starting at offset
off. Will update off to where the buf has been decoded. Stops decoding
/* Returns an allocated hex-decoded string from the buf. Stops decoding
at end of buf (zero) or when seeing the delim char. */
static
char *decode_hexstring (const char *buf, size_t prefixlen, size_t len)
@ -964,7 +963,7 @@ write_reply(const char *reply)
return write_checksum (reply);
}
/* Creates a packet from a string message, called needs to free. */
/* Creates a packet from a string message, caller needs to free. */
static char *
create_packet(const char *msg)
{
@ -1028,7 +1027,7 @@ static int receive_packet(char *buf, int noackmode)
unsigned char csum = 0;
// Look for first '$' (start of packet) or error.
receive_packet_start:
receive_packet_start:
do {
ret = read_one_char(&c);
if (ret <= 0)
@ -1085,8 +1084,12 @@ static const char *next_delim_string (const char *buf, char delim)
return buf;
}
// Throws away the packet name and decodes the hex string, which is placed in
// decoded_string (the caller owns this and is responsible for freeing it).
/* buf starts with the packet name followed by the delimiter, for example
* vRun;2f62696e2f6c73, ";" is the delimiter here, or
* qXfer:features:read:target.xml:0,1000, where the delimiter is ":".
* The packet name is thrown away and the hex string is decoded and
* is placed in decoded_string (the caller owns this and is responsible
* for freeing it). */
static int split_hexdecode(const char *buf, const char *string,
const char *delim, char **decoded_string)
{
@ -1101,7 +1104,7 @@ static int split_hexdecode(const char *buf, const char *string,
}
}
static int count_delims(char delim, char *buf)
static size_t count_delims(char delim, char *buf)
{
size_t count = 0;
char *ptr = buf;
@ -1298,7 +1301,7 @@ void do_multi_mode(void)
break;
}
DEBUG(1, "packet recieved: '%s'\n", buf);
DEBUG(1, "packet received: '%s'\n", buf);
#define QSUPPORTED "qSupported:"
#define STARTNOACKMODE "QStartNoAckMode"
@ -1403,7 +1406,8 @@ void do_multi_mode(void)
if (i < count - 1)
next_str = next_delim_string(next_str, *delim);
}
DEBUG(1, "vRun decoded: %s, next_str %s, len[%d] %d\n", decoded_string[i], next_str, i, len[i]);
DEBUG(1, "vRun decoded: %s, next_str %s, len[%d] %d\n",
decoded_string[i], next_str, i, len[i]);
}
/* If we didn't get any arguments or the filename is an empty
@ -1431,8 +1435,9 @@ void do_multi_mode(void)
// Lets report we Stopped with SIGTRAP (05).
send_packet ("S05", noackmode);
prepare_fifos_and_shared_mem(valgrind_pid);
DEBUG(1, "from_gdb_to_pid %s, to_gdb_from_pid %s\n", from_gdb_to_pid, to_gdb_from_pid);
// gdb_rely is an endless loop till valgrind quits.
DEBUG(1, "from_gdb_to_pid %s, to_gdb_from_pid %s\n",
from_gdb_to_pid, to_gdb_from_pid);
// gdb_relay is an endless loop till valgrind quits.
shutting_down = False;
gdb_relay (valgrind_pid, 1, q_buf);
@ -1451,7 +1456,7 @@ void do_multi_mode(void)
DEBUG(1, "valgrind kill by signal %d\n",
WTERMSIG(status));
else
DEBUG(1, "valgind unexpectedly stopped or continued");
DEBUG(1, "valgrind unexpectedly stopped or continued");
}
} else {
send_packet ("E01", noackmode);
@ -1481,9 +1486,10 @@ void do_multi_mode(void)
DEBUG(1, "qAttached decoding error: strdup of %s failed!\n", buf);
continue;
}
} /* Reset the state of environment variables in the remote target before starting
the inferior. In this context, reset means unsetting all environment variables
that were previously set by the user (i.e., were not initially present in the environment). */
} /* Reset the state of environment variables in the remote target
before starting the inferior. In this context, reset means
unsetting all environment variables that were previously set
by the user (i.e., were not initially present in the environment). */
else if (strncmp(QENVIRONMENTRESET, buf,
strlen(QENVIRONMENTRESET)) == 0) {
send_packet ("OK", noackmode);
@ -1495,7 +1501,7 @@ void do_multi_mode(void)
if (!split_hexdecode(buf, QENVIRONMENTHEXENCODED, ":", &string))
break;
// TODO Collect all environment strings and add them to environ
// before launcing valgrind.
// before launching valgrind.
free (string);
string = NULL;
} else if (strncmp(QENVIRONMENTUNSET, buf,
@ -2220,7 +2226,8 @@ void parse_options(int argc, char** argv,
/* Compute the absolute path. */
valgrind_path = realpath(path, NULL);
if (!valgrind_path) {
TSFPRINTF(stderr, "%s is not a correct path. %s, exiting.\n", path, strerror (errno));
TSFPRINTF(stderr, "%s is not a correct path. %s, exiting.\n",
path, strerror (errno));
exit(1);
}
DEBUG(2, "valgrind's real path: %s\n", valgrind_path);
@ -2228,7 +2235,7 @@ void parse_options(int argc, char** argv,
// Everything that follows now is an argument for valgrind
// No other options (or commands) can follow
// argc - i is the number of left over arguments
// allocate enough space, but all args in it.
// allocate enough space, put all args in it.
cvargs = argc - i - 1;
vargs = vmalloc (cvargs * sizeof(vargs));
i++;

View File

@ -1299,8 +1299,8 @@ It has three usage modes:
</listitem>
<listitem id="manual-core-adv.vgdb-multi" xreflabel="vgdb multi">
<para>In the <option>--multi</option> mode, Vgdb uses the extended
remote protocol to communicate with Gdb. This allows you to view
<para>In the <option>--multi</option> mode, vgdb uses the extended
remote protocol to communicate with GDB. This allows you to view
output from both valgrind and GDB in the GDB session. This is
accomplished via the "target extended-remote | vgdb --multi". In
this mode you no longer need to start valgrind yourself. vgdb will
@ -2271,5 +2271,4 @@ almost 300 different wrappers.</para>
</chapter>

View File

@ -190,7 +190,6 @@ usage: valgrind [options] prog-and-args
--progress-interval=<number> report progress every <number>
CPU seconds [0, meaning disabled]
--command-line-only=no|yes only use command line options [no]
--launched-with-multi=no|yes valgrind launched in vgdb multi mode [no]
Vex options for all Valgrind tools:
--vex-iropt-verbosity=<0..9> [0]

View File

@ -188,7 +188,6 @@ usage: valgrind [options] prog-and-args
--progress-interval=<number> report progress every <number>
CPU seconds [0, meaning disabled]
--command-line-only=no|yes only use command line options [no]
--launched-with-multi=no|yes valgrind launched in vgdb multi mode [no]
Vex options for all Valgrind tools:
--vex-iropt-verbosity=<0..9> [0]