diff mbox

Define an error function in the PPC simulator.

Message ID 20161124152917.52189-1-jhb@FreeBSD.org
State New
Headers show

Commit Message

John Baldwin Nov. 24, 2016, 3:29 p.m. UTC
Previously this used the error function from GDB directly instead of
the error method in the host callbacks structure.  This was exposed via
a link error when GDB was converted to C++.  The error function invokes
the error callback similar to sim_io_error.

sim/ppc/ChangeLog:

	* sim_calls.c (error): New function.
---
 sim/ppc/ChangeLog   |  4 ++++
 sim/ppc/sim_calls.c | 10 ++++++++++
 2 files changed, 14 insertions(+)

Comments

Mike Frysinger Nov. 25, 2016, 4:49 p.m. UTC | #1
On 24 Nov 2016 07:29, John Baldwin wrote:
> Previously this used the error function from GDB directly instead of
> the error method in the host callbacks structure.  This was exposed via
> a link error when GDB was converted to C++.  The error function invokes
> the error callback similar to sim_io_error.

ppc/main.c and ppc/misc.c already have error() definitions
-mike
John Baldwin Nov. 25, 2016, 5:21 p.m. UTC | #2
On Friday, November 25, 2016 08:49:08 AM Mike Frysinger wrote:
> On 24 Nov 2016 07:29, John Baldwin wrote:
> > Previously this used the error function from GDB directly instead of
> > the error method in the host callbacks structure.  This was exposed via
> > a link error when GDB was converted to C++.  The error function invokes
> > the error callback similar to sim_io_error.
> 
> ppc/main.c and ppc/misc.c already have error() definitions

Yes, though those are not included when libsim is linked into gdb itself.
misc.o is explicitly included for certain binaries in sim/ppc/Makefile.in.
Note that zalloc() is defined in both misc.c and sim_calls.c as well, I
suspect for similar reasons.

Looking at main.c, it overrides various symbols (sim_io_*, also
zalloc) that are defined in sim_calls.c with local versions.  (Perhaps
psim should not be linking sim_calls.o in at all?)  'error' is another
such symbol.
Mike Frysinger Nov. 26, 2016, 10:19 p.m. UTC | #3
On 25 Nov 2016 09:21, John Baldwin wrote:
> On Friday, November 25, 2016 08:49:08 AM Mike Frysinger wrote:
> > On 24 Nov 2016 07:29, John Baldwin wrote:
> > > Previously this used the error function from GDB directly instead of
> > > the error method in the host callbacks structure.  This was exposed via
> > > a link error when GDB was converted to C++.  The error function invokes
> > > the error callback similar to sim_io_error.
> > 
> > ppc/main.c and ppc/misc.c already have error() definitions
> 
> Yes, though those are not included when libsim is linked into gdb itself.
> misc.o is explicitly included for certain binaries in sim/ppc/Makefile.in.
> Note that zalloc() is defined in both misc.c and sim_calls.c as well, I
> suspect for similar reasons.
> 
> Looking at main.c, it overrides various symbols (sim_io_*, also
> zalloc) that are defined in sim_calls.c with local versions.  (Perhaps
> psim should not be linking sim_calls.o in at all?)  'error' is another
> such symbol.

yes, the ppc sim is a bit of mess due to its history.  i'm not sure we
should just keep throwing onto the pile though.

if psim/main.c doesn't need it, then dropping it sounds easy enough.
-mike
John Baldwin Dec. 6, 2016, 7:08 p.m. UTC | #4
On Saturday, November 26, 2016 02:19:46 PM Mike Frysinger wrote:
> On 25 Nov 2016 09:21, John Baldwin wrote:
> > On Friday, November 25, 2016 08:49:08 AM Mike Frysinger wrote:
> > > On 24 Nov 2016 07:29, John Baldwin wrote:
> > > > Previously this used the error function from GDB directly instead of
> > > > the error method in the host callbacks structure.  This was exposed via
> > > > a link error when GDB was converted to C++.  The error function invokes
> > > > the error callback similar to sim_io_error.
> > > 
> > > ppc/main.c and ppc/misc.c already have error() definitions
> > 
> > Yes, though those are not included when libsim is linked into gdb itself.
> > misc.o is explicitly included for certain binaries in sim/ppc/Makefile.in.
> > Note that zalloc() is defined in both misc.c and sim_calls.c as well, I
> > suspect for similar reasons.
> > 
> > Looking at main.c, it overrides various symbols (sim_io_*, also
> > zalloc) that are defined in sim_calls.c with local versions.  (Perhaps
> > psim should not be linking sim_calls.o in at all?)  'error' is another
> > such symbol.
> 
> yes, the ppc sim is a bit of mess due to its history.  i'm not sure we
> should just keep throwing onto the pile though.
> 
> if psim/main.c doesn't need it, then dropping it sounds easy enough.

I misread the Makefiles a bit and psim doesn't link in sim_calls.o, so it
still needs its own zalloc() and error() in main.c.

In particular, ppc/Makefile generates the libsim.a that gdb links against
which includes sim_calls.o (via GDB_OBJ) but not main.o or misc.o.  The
psim binary includes main.o (but not sim_calls.o or misc.o), and the other
binaries (igen, dgen, tmp-filter) include misc.o (but not sim_calls.o or
main.o).

While it might make sense to merge bits of main.c with misc.c, I think the
GDB-specific functions in sim_calls.c are always going to be required
(including a custom error() that invokes GDB's error hook).
John Baldwin Dec. 23, 2016, 9:26 p.m. UTC | #5
On Tuesday, December 06, 2016 11:08:07 AM John Baldwin wrote:
> On Saturday, November 26, 2016 02:19:46 PM Mike Frysinger wrote:
> > On 25 Nov 2016 09:21, John Baldwin wrote:
> > > On Friday, November 25, 2016 08:49:08 AM Mike Frysinger wrote:
> > > > On 24 Nov 2016 07:29, John Baldwin wrote:
> > > > > Previously this used the error function from GDB directly instead of
> > > > > the error method in the host callbacks structure.  This was exposed via
> > > > > a link error when GDB was converted to C++.  The error function invokes
> > > > > the error callback similar to sim_io_error.
> > > > 
> > > > ppc/main.c and ppc/misc.c already have error() definitions
> > > 
> > > Yes, though those are not included when libsim is linked into gdb itself.
> > > misc.o is explicitly included for certain binaries in sim/ppc/Makefile.in.
> > > Note that zalloc() is defined in both misc.c and sim_calls.c as well, I
> > > suspect for similar reasons.
> > > 
> > > Looking at main.c, it overrides various symbols (sim_io_*, also
> > > zalloc) that are defined in sim_calls.c with local versions.  (Perhaps
> > > psim should not be linking sim_calls.o in at all?)  'error' is another
> > > such symbol.
> > 
> > yes, the ppc sim is a bit of mess due to its history.  i'm not sure we
> > should just keep throwing onto the pile though.
> > 
> > if psim/main.c doesn't need it, then dropping it sounds easy enough.
> 
> I misread the Makefiles a bit and psim doesn't link in sim_calls.o, so it
> still needs its own zalloc() and error() in main.c.
> 
> In particular, ppc/Makefile generates the libsim.a that gdb links against
> which includes sim_calls.o (via GDB_OBJ) but not main.o or misc.o.  The
> psim binary includes main.o (but not sim_calls.o or misc.o), and the other
> binaries (igen, dgen, tmp-filter) include misc.o (but not sim_calls.o or
> main.o).
> 
> While it might make sense to merge bits of main.c with misc.c, I think the
> GDB-specific functions in sim_calls.c are always going to be required
> (including a custom error() that invokes GDB's error hook).

*ping* (This fixes PR sim/20863 btw)
diff mbox

Patch

diff --git a/sim/ppc/ChangeLog b/sim/ppc/ChangeLog
index 7ed024e..f7d8ffb 100644
--- a/sim/ppc/ChangeLog
+++ b/sim/ppc/ChangeLog
@@ -1,3 +1,7 @@ 
+2016-11-24  John Baldwin  <jhb@FreeBSD.org>
+
+	* sim_calls.c (error): New function.
+
 2016-01-10  Mike Frysinger  <vapier@gentoo.org>
 
 	* configure.ac (sim-assert): Call AC_MSG_CHECKING,
diff --git a/sim/ppc/sim_calls.c b/sim/ppc/sim_calls.c
index 470c958..eb5d1a7 100644
--- a/sim/ppc/sim_calls.c
+++ b/sim/ppc/sim_calls.c
@@ -386,6 +386,16 @@  sim_io_error (SIM_DESC sd, const char *fmt, ...)
 
 /****/
 
+void NORETURN
+error (const char *msg, ...)
+{
+  va_list ap;
+  va_start(ap, msg);
+  callbacks->evprintf_filtered (callbacks, msg, ap);
+  va_end(ap);
+  callbacks->error (callbacks, "");
+}
+
 void *
 zalloc(long size)
 {