mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-17 16:05:56 +08:00

This rewrites gdb's TRY/CATCH to plain C++ try/catch. The patch was largely written by script, though one change (to a comment in common-exceptions.h) was reverted by hand. gdb/ChangeLog 2019-04-08 Tom Tromey <tom@tromey.com> * xml-support.c: Use C++ exception handling. * x86-linux-nat.c: Use C++ exception handling. * windows-nat.c: Use C++ exception handling. * varobj.c: Use C++ exception handling. * value.c: Use C++ exception handling. * valprint.c: Use C++ exception handling. * valops.c: Use C++ exception handling. * unittests/parse-connection-spec-selftests.c: Use C++ exception handling. * unittests/cli-utils-selftests.c: Use C++ exception handling. * typeprint.c: Use C++ exception handling. * tui/tui.c: Use C++ exception handling. * tracefile-tfile.c: Use C++ exception handling. * top.c: Use C++ exception handling. * thread.c: Use C++ exception handling. * target.c: Use C++ exception handling. * symmisc.c: Use C++ exception handling. * symfile-mem.c: Use C++ exception handling. * stack.c: Use C++ exception handling. * sparc64-linux-tdep.c: Use C++ exception handling. * solib.c: Use C++ exception handling. * solib-svr4.c: Use C++ exception handling. * solib-spu.c: Use C++ exception handling. * solib-frv.c: Use C++ exception handling. * solib-dsbt.c: Use C++ exception handling. * selftest-arch.c: Use C++ exception handling. * s390-tdep.c: Use C++ exception handling. * rust-lang.c: Use C++ exception handling. * rust-exp.y: Use C++ exception handling. * rs6000-tdep.c: Use C++ exception handling. * rs6000-aix-tdep.c: Use C++ exception handling. * riscv-tdep.c: Use C++ exception handling. * remote.c: Use C++ exception handling. * remote-fileio.c: Use C++ exception handling. * record-full.c: Use C++ exception handling. * record-btrace.c: Use C++ exception handling. * python/python.c: Use C++ exception handling. * python/py-value.c: Use C++ exception handling. * python/py-utils.c: Use C++ exception handling. * python/py-unwind.c: Use C++ exception handling. * python/py-type.c: Use C++ exception handling. * python/py-symbol.c: Use C++ exception handling. * python/py-record.c: Use C++ exception handling. * python/py-record-btrace.c: Use C++ exception handling. * python/py-progspace.c: Use C++ exception handling. * python/py-prettyprint.c: Use C++ exception handling. * python/py-param.c: Use C++ exception handling. * python/py-objfile.c: Use C++ exception handling. * python/py-linetable.c: Use C++ exception handling. * python/py-lazy-string.c: Use C++ exception handling. * python/py-infthread.c: Use C++ exception handling. * python/py-inferior.c: Use C++ exception handling. * python/py-gdb-readline.c: Use C++ exception handling. * python/py-framefilter.c: Use C++ exception handling. * python/py-frame.c: Use C++ exception handling. * python/py-finishbreakpoint.c: Use C++ exception handling. * python/py-cmd.c: Use C++ exception handling. * python/py-breakpoint.c: Use C++ exception handling. * python/py-arch.c: Use C++ exception handling. * printcmd.c: Use C++ exception handling. * ppc-linux-tdep.c: Use C++ exception handling. * parse.c: Use C++ exception handling. * p-valprint.c: Use C++ exception handling. * objc-lang.c: Use C++ exception handling. * mi/mi-main.c: Use C++ exception handling. * mi/mi-interp.c: Use C++ exception handling. * mi/mi-cmd-stack.c: Use C++ exception handling. * mi/mi-cmd-break.c: Use C++ exception handling. * main.c: Use C++ exception handling. * linux-thread-db.c: Use C++ exception handling. * linux-tdep.c: Use C++ exception handling. * linux-nat.c: Use C++ exception handling. * linux-fork.c: Use C++ exception handling. * linespec.c: Use C++ exception handling. * language.c: Use C++ exception handling. * jit.c: Use C++ exception handling. * infrun.c: Use C++ exception handling. * infcmd.c: Use C++ exception handling. * infcall.c: Use C++ exception handling. * inf-loop.c: Use C++ exception handling. * i386-tdep.c: Use C++ exception handling. * i386-linux-tdep.c: Use C++ exception handling. * guile/scm-value.c: Use C++ exception handling. * guile/scm-type.c: Use C++ exception handling. * guile/scm-symtab.c: Use C++ exception handling. * guile/scm-symbol.c: Use C++ exception handling. * guile/scm-pretty-print.c: Use C++ exception handling. * guile/scm-ports.c: Use C++ exception handling. * guile/scm-param.c: Use C++ exception handling. * guile/scm-math.c: Use C++ exception handling. * guile/scm-lazy-string.c: Use C++ exception handling. * guile/scm-frame.c: Use C++ exception handling. * guile/scm-disasm.c: Use C++ exception handling. * guile/scm-cmd.c: Use C++ exception handling. * guile/scm-breakpoint.c: Use C++ exception handling. * guile/scm-block.c: Use C++ exception handling. * guile/guile-internal.h: Use C++ exception handling. * gnu-v3-abi.c: Use C++ exception handling. * gdbtypes.c: Use C++ exception handling. * frame.c: Use C++ exception handling. * frame-unwind.c: Use C++ exception handling. * fbsd-tdep.c: Use C++ exception handling. * f-valprint.c: Use C++ exception handling. * exec.c: Use C++ exception handling. * event-top.c: Use C++ exception handling. * event-loop.c: Use C++ exception handling. * eval.c: Use C++ exception handling. * dwarf2read.c: Use C++ exception handling. * dwarf2loc.c: Use C++ exception handling. * dwarf2-frame.c: Use C++ exception handling. * dwarf2-frame-tailcall.c: Use C++ exception handling. * dwarf-index-write.c: Use C++ exception handling. * dwarf-index-cache.c: Use C++ exception handling. * dtrace-probe.c: Use C++ exception handling. * disasm-selftests.c: Use C++ exception handling. * darwin-nat.c: Use C++ exception handling. * cp-valprint.c: Use C++ exception handling. * cp-support.c: Use C++ exception handling. * cp-abi.c: Use C++ exception handling. * corelow.c: Use C++ exception handling. * completer.c: Use C++ exception handling. * compile/compile-object-run.c: Use C++ exception handling. * compile/compile-object-load.c: Use C++ exception handling. * compile/compile-cplus-symbols.c: Use C++ exception handling. * compile/compile-c-symbols.c: Use C++ exception handling. * common/selftest.c: Use C++ exception handling. * common/new-op.c: Use C++ exception handling. * cli/cli-script.c: Use C++ exception handling. * cli/cli-interp.c: Use C++ exception handling. * cli/cli-cmds.c: Use C++ exception handling. * c-varobj.c: Use C++ exception handling. * btrace.c: Use C++ exception handling. * breakpoint.c: Use C++ exception handling. * break-catch-throw.c: Use C++ exception handling. * arch-utils.c: Use C++ exception handling. * amd64-tdep.c: Use C++ exception handling. * ada-valprint.c: Use C++ exception handling. * ada-typeprint.c: Use C++ exception handling. * ada-lang.c: Use C++ exception handling. * aarch64-tdep.c: Use C++ exception handling. gdb/gdbserver/ChangeLog 2019-04-08 Tom Tromey <tom@tromey.com> * server.c: Use C++ exception handling. * linux-low.c: Use C++ exception handling. * gdbreplay.c: Use C++ exception handling.
252 lines
8.7 KiB
C
252 lines
8.7 KiB
C
/* Self tests for parsing connection specs for GDB, the GNU debugger.
|
|
|
|
Copyright (C) 2018-2019 Free Software Foundation, Inc.
|
|
|
|
This file is part of GDB.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
#include "defs.h"
|
|
#include "common/selftest.h"
|
|
#include "common/netstuff.h"
|
|
#include "diagnostics.h"
|
|
#ifdef USE_WIN32API
|
|
#if _WIN32_WINNT < 0x0501
|
|
# undef _WIN32_WINNT
|
|
# define _WIN32_WINNT 0x0501
|
|
#endif
|
|
#include <ws2tcpip.h>
|
|
#else
|
|
#include <netinet/in.h>
|
|
#include <arpa/inet.h>
|
|
#include <netdb.h>
|
|
#include <sys/socket.h>
|
|
#include <netinet/tcp.h>
|
|
#endif
|
|
|
|
namespace selftests {
|
|
namespace parse_connection_spec_tests {
|
|
|
|
/* Auxiliary struct that holds info about a specific test for a
|
|
connection spec. */
|
|
|
|
struct parse_conn_test
|
|
{
|
|
/* The connection spec. */
|
|
const char *connspec;
|
|
|
|
/* Expected result from 'parse_connection_spec'. */
|
|
parsed_connection_spec expected_result;
|
|
|
|
/* True if this test should fail, false otherwise. If true, only
|
|
the CONNSPEC field should be considered as valid. */
|
|
bool should_fail;
|
|
|
|
/* The expected AI_FAMILY to be found on the 'struct addrinfo'
|
|
HINT. */
|
|
int exp_ai_family;
|
|
|
|
/* The expected AI_SOCKTYPE to be found on the 'struct addrinfo'
|
|
HINT. */
|
|
int exp_ai_socktype;
|
|
|
|
/* The expected AI_PROTOCOL to be found on the 'struct addrinfo'
|
|
HINT. */
|
|
int exp_ai_protocol;
|
|
};
|
|
|
|
/* Some defines to help us fill a 'struct parse_conn_test'. */
|
|
|
|
/* Initialize a full entry. */
|
|
#define INIT_ENTRY(ADDR, EXP_HOST, EXP_PORT, SHOULD_FAIL, EXP_AI_FAMILY, \
|
|
EXP_AI_SOCKTYPE, EXP_AI_PROTOCOL) \
|
|
{ ADDR, { EXP_HOST, EXP_PORT }, SHOULD_FAIL, EXP_AI_FAMILY, \
|
|
EXP_AI_SOCKTYPE, EXP_AI_PROTOCOL }
|
|
|
|
/* Initialize an unprefixed entry. In this case, we don't expect
|
|
anything on the 'struct addrinfo' HINT. */
|
|
#define INIT_UNPREFIXED_ENTRY(ADDR, EXP_HOST, EXP_PORT) \
|
|
INIT_ENTRY (ADDR, EXP_HOST, EXP_PORT, false, 0, 0, 0)
|
|
|
|
/* Initialized an unprefixed IPv6 entry. In this case, we don't
|
|
expect anything on the 'struct addrinfo' HINT. */
|
|
#define INIT_UNPREFIXED_IPV6_ENTRY(ADDR, EXP_HOST, EXP_PORT) \
|
|
INIT_ENTRY (ADDR, EXP_HOST, EXP_PORT, false, AF_INET6, 0, 0)
|
|
|
|
/* Initialize a prefixed entry. */
|
|
#define INIT_PREFIXED_ENTRY(ADDR, EXP_HOST, EXP_PORT, EXP_AI_FAMILY, \
|
|
EXP_AI_SOCKTYPE, EXP_AI_PROTOCOL) \
|
|
INIT_ENTRY (ADDR, EXP_HOST, EXP_PORT, false, EXP_AI_FAMILY, \
|
|
EXP_AI_SOCKTYPE, EXP_AI_PROTOCOL)
|
|
|
|
/* Initialize an entry prefixed with "tcp4:". */
|
|
#define INIT_PREFIXED_IPV4_TCP(ADDR, EXP_HOST, EXP_PORT) \
|
|
INIT_PREFIXED_ENTRY (ADDR, EXP_HOST, EXP_PORT, AF_INET, SOCK_STREAM, \
|
|
IPPROTO_TCP)
|
|
|
|
/* Initialize an entry prefixed with "tcp6:". */
|
|
#define INIT_PREFIXED_IPV6_TCP(ADDR, EXP_HOST, EXP_PORT) \
|
|
INIT_PREFIXED_ENTRY (ADDR, EXP_HOST, EXP_PORT, AF_INET6, SOCK_STREAM, \
|
|
IPPROTO_TCP)
|
|
|
|
/* Initialize an entry prefixed with "udp4:". */
|
|
#define INIT_PREFIXED_IPV4_UDP(ADDR, EXP_HOST, EXP_PORT) \
|
|
INIT_PREFIXED_ENTRY (ADDR, EXP_HOST, EXP_PORT, AF_INET, SOCK_DGRAM, \
|
|
IPPROTO_UDP)
|
|
|
|
/* Initialize an entry prefixed with "udp6:". */
|
|
#define INIT_PREFIXED_IPV6_UDP(ADDR, EXP_HOST, EXP_PORT) \
|
|
INIT_PREFIXED_ENTRY (ADDR, EXP_HOST, EXP_PORT, AF_INET6, SOCK_DGRAM, \
|
|
IPPROTO_UDP)
|
|
|
|
/* Initialize a bogus entry, i.e., a connection spec that should
|
|
fail. */
|
|
#define INIT_BOGUS_ENTRY(ADDR) \
|
|
INIT_ENTRY (ADDR, "", "", true, 0, 0, 0)
|
|
|
|
/* The variable which holds all of our tests. */
|
|
|
|
static const parse_conn_test conn_test[] =
|
|
{
|
|
/* Unprefixed addresses. */
|
|
|
|
/* IPv4, host and port present. */
|
|
INIT_UNPREFIXED_ENTRY ("127.0.0.1:1234", "127.0.0.1", "1234"),
|
|
/* IPv4, only host. */
|
|
INIT_UNPREFIXED_ENTRY ("127.0.0.1", "127.0.0.1", ""),
|
|
/* IPv4, missing port. */
|
|
INIT_UNPREFIXED_ENTRY ("127.0.0.1:", "127.0.0.1", ""),
|
|
|
|
/* IPv6, host and port present, no brackets. */
|
|
INIT_UNPREFIXED_ENTRY ("::1:1234", "::1", "1234"),
|
|
/* IPv6, missing port, no brackets. */
|
|
INIT_UNPREFIXED_ENTRY ("::1:", "::1", ""),
|
|
/* IPv6, host and port present, with brackets. */
|
|
INIT_UNPREFIXED_IPV6_ENTRY ("[::1]:1234", "::1", "1234"),
|
|
/* IPv6, only host, with brackets. */
|
|
INIT_UNPREFIXED_IPV6_ENTRY ("[::1]", "::1", ""),
|
|
/* IPv6, missing port, with brackets. */
|
|
INIT_UNPREFIXED_IPV6_ENTRY ("[::1]:", "::1", ""),
|
|
|
|
/* Unspecified, only port. */
|
|
INIT_UNPREFIXED_ENTRY (":1234", "localhost", "1234"),
|
|
|
|
/* Prefixed addresses. */
|
|
|
|
/* Prefixed "tcp4:" IPv4, host and port presents. */
|
|
INIT_PREFIXED_IPV4_TCP ("tcp4:127.0.0.1:1234", "127.0.0.1", "1234"),
|
|
/* Prefixed "tcp4:" IPv4, only port. */
|
|
INIT_PREFIXED_IPV4_TCP ("tcp4::1234", "localhost", "1234"),
|
|
/* Prefixed "tcp4:" IPv4, only host. */
|
|
INIT_PREFIXED_IPV4_TCP ("tcp4:127.0.0.1", "127.0.0.1", ""),
|
|
/* Prefixed "tcp4:" IPv4, missing port. */
|
|
INIT_PREFIXED_IPV4_TCP ("tcp4:127.0.0.1:", "127.0.0.1", ""),
|
|
|
|
/* Prefixed "udp4:" IPv4, host and port present. */
|
|
INIT_PREFIXED_IPV4_UDP ("udp4:127.0.0.1:1234", "127.0.0.1", "1234"),
|
|
/* Prefixed "udp4:" IPv4, only port. */
|
|
INIT_PREFIXED_IPV4_UDP ("udp4::1234", "localhost", "1234"),
|
|
/* Prefixed "udp4:" IPv4, only host. */
|
|
INIT_PREFIXED_IPV4_UDP ("udp4:127.0.0.1", "127.0.0.1", ""),
|
|
/* Prefixed "udp4:" IPv4, missing port. */
|
|
INIT_PREFIXED_IPV4_UDP ("udp4:127.0.0.1:", "127.0.0.1", ""),
|
|
|
|
|
|
/* Prefixed "tcp6:" IPv6, host and port present. */
|
|
INIT_PREFIXED_IPV6_TCP ("tcp6:::1:1234", "::1", "1234"),
|
|
/* Prefixed "tcp6:" IPv6, only port. */
|
|
INIT_PREFIXED_IPV6_TCP ("tcp6::1234", "localhost", "1234"),
|
|
/* Prefixed "tcp6:" IPv6, only host. */
|
|
//INIT_PREFIXED_IPV6_TCP ("tcp6:::1", "::1", ""),
|
|
/* Prefixed "tcp6:" IPv6, missing port. */
|
|
INIT_PREFIXED_IPV6_TCP ("tcp6:::1:", "::1", ""),
|
|
|
|
/* Prefixed "udp6:" IPv6, host and port present. */
|
|
INIT_PREFIXED_IPV6_UDP ("udp6:::1:1234", "::1", "1234"),
|
|
/* Prefixed "udp6:" IPv6, only port. */
|
|
INIT_PREFIXED_IPV6_UDP ("udp6::1234", "localhost", "1234"),
|
|
/* Prefixed "udp6:" IPv6, only host. */
|
|
//INIT_PREFIXED_IPV6_UDP ("udp6:::1", "::1", ""),
|
|
/* Prefixed "udp6:" IPv6, missing port. */
|
|
INIT_PREFIXED_IPV6_UDP ("udp6:::1:", "::1", ""),
|
|
|
|
/* Prefixed "tcp6:" IPv6 with brackets, host and port present. */
|
|
INIT_PREFIXED_IPV6_TCP ("tcp6:[::1]:1234", "::1", "1234"),
|
|
/* Prefixed "tcp6:" IPv6 with brackets, only host. */
|
|
INIT_PREFIXED_IPV6_TCP ("tcp6:[::1]", "::1", ""),
|
|
/* Prefixed "tcp6:" IPv6 with brackets, missing port. */
|
|
INIT_PREFIXED_IPV6_TCP ("tcp6:[::1]:", "::1", ""),
|
|
|
|
/* Prefixed "udp6:" IPv6 with brackets, host and port present. */
|
|
INIT_PREFIXED_IPV6_UDP ("udp6:[::1]:1234", "::1", "1234"),
|
|
/* Prefixed "udp6:" IPv6 with brackets, only host. */
|
|
INIT_PREFIXED_IPV6_UDP ("udp6:[::1]", "::1", ""),
|
|
/* Prefixed "udp6:" IPv6 with brackets, missing port. */
|
|
INIT_PREFIXED_IPV6_UDP ("udp6:[::1]:", "::1", ""),
|
|
|
|
|
|
/* Bogus addresses. */
|
|
INIT_BOGUS_ENTRY ("tcp6:[::1]123:44"),
|
|
INIT_BOGUS_ENTRY ("[::1"),
|
|
INIT_BOGUS_ENTRY ("tcp6:::1]:"),
|
|
};
|
|
|
|
/* Test a connection spec C. */
|
|
|
|
static void
|
|
test_conn (const parse_conn_test &c)
|
|
{
|
|
struct addrinfo hint;
|
|
parsed_connection_spec ret;
|
|
|
|
memset (&hint, 0, sizeof (hint));
|
|
|
|
try
|
|
{
|
|
ret = parse_connection_spec (c.connspec, &hint);
|
|
}
|
|
catch (const gdb_exception_RETURN_MASK_ERROR &ex)
|
|
{
|
|
/* If we caught an error, we should check if this connection
|
|
spec was supposed to fail. */
|
|
SELF_CHECK (c.should_fail);
|
|
return;
|
|
}
|
|
|
|
SELF_CHECK (!c.should_fail);
|
|
SELF_CHECK (ret.host_str == c.expected_result.host_str);
|
|
SELF_CHECK (ret.port_str == c.expected_result.port_str);
|
|
SELF_CHECK (hint.ai_family == c.exp_ai_family);
|
|
SELF_CHECK (hint.ai_socktype == c.exp_ai_socktype);
|
|
SELF_CHECK (hint.ai_protocol == c.exp_ai_protocol);
|
|
}
|
|
|
|
/* Run the tests associated with parsing connection specs. */
|
|
|
|
static void
|
|
run_tests ()
|
|
{
|
|
for (const parse_conn_test &c : conn_test)
|
|
test_conn (c);
|
|
}
|
|
} /* namespace parse_connection_spec_tests */
|
|
} /* namespace selftests */
|
|
|
|
void
|
|
_initialize_parse_connection_spec_selftests ()
|
|
{
|
|
selftests::register_test ("parse_connection_spec",
|
|
selftests::parse_connection_spec_tests::run_tests);
|
|
}
|