Best way to check whether the "sim" is running standalone or by GDB

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Best way to check whether the "sim" is running standalone or by GDB

William Tambe
What is the best way to check whether the "sim" is running standalone
or by GDB ?
Reply | Threaded
Open this post in threaded view
|

Re: Best way to check whether the "sim" is running standalone or by GDB

William Tambe
To clarify further my question, I would like to be able to issue the
following only when the sim is being run by GDB:
sim_engine_halt (sim_stopped, SIM_SIGTRAP);

On Wed, Aug 28, 2019 at 9:15 PM William Tambe <[hidden email]> wrote:
>
> What is the best way to check whether the "sim" is running standalone
> or by GDB ?
Reply | Threaded
Open this post in threaded view
|

Re: Best way to check whether the "sim" is running standalone or by GDB

Nick Clifton
Hi William,

>> What is the best way to check whether the "sim" is running standalone
>> or by GDB ?

Possibly not the best way, but one way is to use a global variable to
indicate the presence of the standalone driver.  eg:

  int running_standalone = 0;

  ...
    if (! running_standalone)
      sim_engine_halt (sim_stopped, SIM_SIGTRAP);

Then in your standalone code, initialise the variable to non-zero.

Cheers
  Nick




Reply | Threaded
Open this post in threaded view
|

Re: Best way to check whether the "sim" is running standalone or by GDB

William Tambe
On Fri, Aug 30, 2019 at 4:54 AM Nick Clifton <[hidden email]> wrote:

>
> Hi William,
>
> >> What is the best way to check whether the "sim" is running standalone
> >> or by GDB ?
>
> Possibly not the best way, but one way is to use a global variable to
> indicate the presence of the standalone driver.  eg:
>
>   int running_standalone = 0;
>
>   ...
>     if (! running_standalone)
>       sim_engine_halt (sim_stopped, SIM_SIGTRAP);
>
> Then in your standalone code, initialise the variable to non-zero.

What constitute the standalone code ?

in fact, to port the simulator, I only had to implement the following:
sim_engine_run ()
sim_open ()
sim_create_inferior ()

All the above functions are both used when the sim is running
"standalone" or by "GDB".

Is there another function I can define that will only be used when the
sim is running "standalone" ?

>
> Cheers
>   Nick
>
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Best way to check whether the "sim" is running standalone or by GDB

Nick Clifton
Hi William,

> What constitute the standalone code ?>
> in fact, to port the simulator, I only had to implement the following:
> sim_engine_run ()
> sim_open ()
> sim_create_inferior ()
>
> All the above functions are both used when the sim is running
> "standalone" or by "GDB".
>
> Is there another function I can define that will only be used when the
> sim is running "standalone" ?

Presumably you are using a Makefile.in like the other simulators.
In there you define SIM_RUN_OBJS to contain the object files that
are only part of the standalone simulator.  So you could use a
function in one of those object files.  main() would be the obvious
choice, if you are using your own.  Or else something called from
the main() defined in common/nrun.c.

Cheers
  Nick


Reply | Threaded
Open this post in threaded view
|

Re: Best way to check whether the "sim" is running standalone or by GDB

Michael Morrell
In reply to this post by William Tambe
William,

> What is the best way to check whether the "sim" is running standalone or by GDB ?

In sim_open, the first parameter is "SIM_OPEN_KIND kind".  When sim_open is called in standalone (i.e., from nrun.c), this parameter is SIM_OPEN_STANDALONE) and when called from GDB, it is SIM_OPEN_DEBUG.  This can be saved and checked later.

A typical call in sim_open is:

SIM_DESC sd = sim_state_alloc(kind, callback);

which saves kind in the sd structure.  You can use STATE_OPEN_KIND(sd) to examine it in any function that receives an "sd".

Hope this helps.

   Michael