aboutsummaryrefslogtreecommitdiff
path: root/gdb/serial.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2023-09-01 12:11:37 -0600
committerTom Tromey <tromey@adacore.com>2023-11-27 12:55:14 -0700
commita2e0acea420cca881296c6fcf58920f3d7c05a45 (patch)
tree54f369a7b5a2ead36e15f14e2d0d154a30286fab /gdb/serial.c
parentad3cf8c64e6e4794fc48d28c90f20cbbfdc51ca4 (diff)
downloadgdb-a2e0acea420cca881296c6fcf58920f3d7c05a45.zip
gdb-a2e0acea420cca881296c6fcf58920f3d7c05a45.tar.gz
gdb-a2e0acea420cca881296c6fcf58920f3d7c05a45.tar.bz2
Change serial "open" functions to throw exception
remote.c assumes that a failure to open the serial connection will set errno. This is somewhat true, because the Windows code tries to set errno appropriately -- but only somewhat, because it isn't clear that the "pex" code sets it, and the tcp code seems to do the wrong thing. It seems better to simply have the serial open functions throw on error. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30770
Diffstat (limited to 'gdb/serial.c')
-rw-r--r--gdb/serial.c32
1 files changed, 11 insertions, 21 deletions
diff --git a/gdb/serial.c b/gdb/serial.c
index 122ab0b..720af1a 100644
--- a/gdb/serial.c
+++ b/gdb/serial.c
@@ -173,12 +173,10 @@ serial_for_fd (int fd)
/* Create a new serial for OPS. */
-static struct serial *
+static gdb::unique_xmalloc_ptr<struct serial>
new_serial (const struct serial_ops *ops)
{
- struct serial *scb;
-
- scb = XCNEW (struct serial);
+ gdb::unique_xmalloc_ptr<struct serial> scb (XCNEW (struct serial));
scb->ops = ops;
@@ -221,7 +219,7 @@ serial_open (const char *name)
}
if (!ops)
- return NULL;
+ error (_("could not find serial handler for '%s'"), name);
return serial_open_ops_1 (ops, open_name);
}
@@ -231,20 +229,14 @@ serial_open (const char *name)
static struct serial *
serial_open_ops_1 (const struct serial_ops *ops, const char *open_name)
{
- struct serial *scb;
-
- scb = new_serial (ops);
+ gdb::unique_xmalloc_ptr<struct serial> scb = new_serial (ops);
/* `...->open (...)' would get expanded by the open(2) syscall macro. */
- if ((*scb->ops->open) (scb, open_name))
- {
- xfree (scb);
- return NULL;
- }
+ (*scb->ops->open) (scb.get (), open_name);
scb->name = open_name != NULL ? xstrdup (open_name) : NULL;
scb->next = scb_base;
- scb_base = scb;
+ scb_base = scb.get ();
if (!serial_logfile.empty ())
{
@@ -256,7 +248,7 @@ serial_open_ops_1 (const struct serial_ops *ops, const char *open_name)
serial_logfp = file.release ();
}
- return scb;
+ return scb.release ();
}
/* See serial.h. */
@@ -273,8 +265,6 @@ serial_open_ops (const struct serial_ops *ops)
static struct serial *
serial_fdopen_ops (const int fd, const struct serial_ops *ops)
{
- struct serial *scb;
-
if (!ops)
{
ops = serial_interface_lookup ("terminal");
@@ -285,18 +275,18 @@ serial_fdopen_ops (const int fd, const struct serial_ops *ops)
if (!ops)
return NULL;
- scb = new_serial (ops);
+ gdb::unique_xmalloc_ptr<struct serial> scb = new_serial (ops);
scb->name = NULL;
scb->next = scb_base;
- scb_base = scb;
+ scb_base = scb.get ();
if ((ops->fdopen) != NULL)
- (*ops->fdopen) (scb, fd);
+ (*ops->fdopen) (scb.get (), fd);
else
scb->fd = fd;
- return scb;
+ return scb.release ();
}
struct serial *