public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Best way to check whether the "sim" is running standalone or by GDB
@ 2019-08-29  2:15 William Tambe
  2019-08-29 18:05 ` William Tambe
  2021-01-15  6:04 ` Mike Frysinger
  0 siblings, 2 replies; 7+ messages in thread
From: William Tambe @ 2019-08-29  2:15 UTC (permalink / raw)
  To: gdb

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Best way to check whether the "sim" is running standalone or by GDB
  2019-08-29  2:15 Best way to check whether the "sim" is running standalone or by GDB William Tambe
@ 2019-08-29 18:05 ` William Tambe
  2019-08-30  9:54   ` Nick Clifton
  2021-01-15  6:04 ` Mike Frysinger
  1 sibling, 1 reply; 7+ messages in thread
From: William Tambe @ 2019-08-29 18:05 UTC (permalink / raw)
  To: gdb

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 <tambewilliam@gmail.com> wrote:
>
> What is the best way to check whether the "sim" is running standalone
> or by GDB ?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Best way to check whether the "sim" is running standalone or by GDB
  2019-08-29 18:05 ` William Tambe
@ 2019-08-30  9:54   ` Nick Clifton
  2019-08-30 15:24     ` William Tambe
  0 siblings, 1 reply; 7+ messages in thread
From: Nick Clifton @ 2019-08-30  9:54 UTC (permalink / raw)
  To: William Tambe, gdb

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




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Best way to check whether the "sim" is running standalone or by GDB
  2019-08-30  9:54   ` Nick Clifton
@ 2019-08-30 15:24     ` William Tambe
  2019-08-30 16:02       ` Nick Clifton
  0 siblings, 1 reply; 7+ messages in thread
From: William Tambe @ 2019-08-30 15:24 UTC (permalink / raw)
  To: Nick Clifton; +Cc: gdb

On Fri, Aug 30, 2019 at 4:54 AM Nick Clifton <nickc@redhat.com> 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
>
>
>
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Best way to check whether the "sim" is running standalone or by GDB
  2019-08-30 15:24     ` William Tambe
@ 2019-08-30 16:02       ` Nick Clifton
  0 siblings, 0 replies; 7+ messages in thread
From: Nick Clifton @ 2019-08-30 16:02 UTC (permalink / raw)
  To: William Tambe; +Cc: gdb

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Best way to check whether the "sim" is running standalone or by GDB
  2019-08-29  2:15 Best way to check whether the "sim" is running standalone or by GDB William Tambe
  2019-08-29 18:05 ` William Tambe
@ 2021-01-15  6:04 ` Mike Frysinger
  1 sibling, 0 replies; 7+ messages in thread
From: Mike Frysinger @ 2021-01-15  6:04 UTC (permalink / raw)
  To: William Tambe; +Cc: gdb

[-- Attachment #1: Type: text/plain, Size: 271 bytes --]

On 28 Aug 2019 21:15, William Tambe wrote:
> What is the best way to check whether the "sim" is running standalone
> or by GDB ?

this is the point of SIM_OPEN_KIND.  it is set to SIM_OPEN_DEBUG when
gdb (a debugger) is used, and SIM_OPEN_STANDALONE when it's not.
-mike

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Best way to check whether the "sim" is running standalone or by GDB
@ 2019-09-03 19:26 Michael Morrell
  0 siblings, 0 replies; 7+ messages in thread
From: Michael Morrell @ 2019-09-03 19:26 UTC (permalink / raw)
  To: gdb

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-01-15  6:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-29  2:15 Best way to check whether the "sim" is running standalone or by GDB William Tambe
2019-08-29 18:05 ` William Tambe
2019-08-30  9:54   ` Nick Clifton
2019-08-30 15:24     ` William Tambe
2019-08-30 16:02       ` Nick Clifton
2021-01-15  6:04 ` Mike Frysinger
2019-09-03 19:26 Michael Morrell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).