public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Libmudflap for sh-elf toolchain cannot access environment variable MUDFLAP_OPTIONS
@ 2007-06-15 10:37 Deepen Mantri
  2007-06-15 11:01 ` Andrew STUBBS
  0 siblings, 1 reply; 7+ messages in thread
From: Deepen Mantri @ 2007-06-15 10:37 UTC (permalink / raw)
  To: Frank Ch. Eigler; +Cc: gcc

Hi,

I successfully built the sh-elf cross compiler on the
x86/linux host enabled with libmudflap by specifying the 
correct entry point in libmudflap's configure file.
(newlib-1.15.0 was used)  
 
I compiled a simple c code with following options on 
linux shell:

sh-elf-gcc -fmudflap test.c -static -lmudflap -o test.out

Then I set the MUDFLAP_OPTIONS environment variable as 
-print-leaks and executed the generated test.out file on
the sh-elf simulator. Nothing got displayed.

Following code snippet from __mf_init() function present
in mf-runtime.c is causing problem:

/////////////////////////////////////////////////////
.
.
ov = getenv ("MUDFLAP_OPTIONS");
  if (ov)
    {
      int rc = __mfu_set_options (ov);
      if (rc < 0)
        {
          __mf_usage ();
          exit (1);
        }
    }

  /* Initialize to a non-zero description epoch. */
  __mf_describe_object (NULL);
.
.
/////////////////////////////////////////////////////

getenv("MUDFLAP_OPTIONS") function call returns NULL 
because __environ is pointing to null terminated pointer
array. Hence the options are not setting. 

How to make x86/linux shell's environment variable 
(MUDFLAP_OPTIONS) accessible to test.out while executing
it through the sh-elf simulator? 

  
Regards,
Deepen Mantri

KPIT Cummins InfoSystems Ltd.
Pune, India

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Free download of GNU based tool-chains for Renesas' SH,H8,
R8C, M16C and M32C Series. The following site also offers 
free technical support to its users. 
Visit http://www.kpitgnutools.com for details.
Latest versions of KPIT GNU tools were released on Feb 6, 07
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

* Re: Libmudflap for sh-elf toolchain cannot access environment variable  MUDFLAP_OPTIONS
  2007-06-15 10:37 Libmudflap for sh-elf toolchain cannot access environment variable MUDFLAP_OPTIONS Deepen Mantri
@ 2007-06-15 11:01 ` Andrew STUBBS
  0 siblings, 0 replies; 7+ messages in thread
From: Andrew STUBBS @ 2007-06-15 11:01 UTC (permalink / raw)
  To: Deepen Mantri; +Cc: Frank Ch. Eigler, gcc

Deepen Mantri wrote:
> How to make x86/linux shell's environment variable 
> (MUDFLAP_OPTIONS) accessible to test.out while executing
> it through the sh-elf simulator? 

I don't know about other targets, but the SH newlib/crt/simulator 
doesn't do anything with the environment.

You could spend ages modifying the simulator and C runtime library to 
have the environment copied to the target.

It's probably easier to place a putenv("MUDFLAP_OPTIONS=blah") in your 
code, or inject it from the debugger.

Andrew

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

* RE: Libmudflap for sh-elf toolchain cannot access environment variable MUDFLAP_OPTIONS
@ 2007-06-15 16:07 Deepen Mantri
  0 siblings, 0 replies; 7+ messages in thread
From: Deepen Mantri @ 2007-06-15 16:07 UTC (permalink / raw)
  To: Frank Ch. Eigler; +Cc: gcc


Frank Eigler wrote:

>You need to teach your simulator to pass environment variables on ...

Thanks for the reply.

To pass on the environment variables from simulator to a.out which 
is targeted for machine different than host would require simulator
to pass the data to a.out (other than command line arguments).
Can we do this?

>Since command line arguments are (sometimes) passed on, perhaps you
>could write a short routine that parses MUDFLAP_OPTIONS from there
>and calls __mf_set_options.

You mean to say that instead of setting environment variable, 
I should pass mudflap runtime controlling options (for eg: -print-leaks)
as command line arguments and add a routine to detect them.

Regards
Deepen Mantri
   
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Free download of GNU based tool-chains for Renesas' SH, H8,
R8C,M16C and M32C Series. The following site also offers free 
technical support to its users. 
Visit http://www.kpitgnutools.com for details.
Latest versions of KPIT GNU tools were released on Feb 6, 07
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

* Re: Libmudflap for sh-elf toolchain cannot access environment variable  MUDFLAP_OPTIONS
  2007-06-15 15:20 Deepen Mantri
  2007-06-15 15:28 ` Frank Ch. Eigler
@ 2007-06-15 15:32 ` Andrew STUBBS
  1 sibling, 0 replies; 7+ messages in thread
From: Andrew STUBBS @ 2007-06-15 15:32 UTC (permalink / raw)
  To: Deepen Mantri; +Cc: Frank Ch. Eigler, gcc

Deepen Mantri wrote:
> We cannot place putenv("MUDFLAP_OPTIONS=<..>") in
> libmudflap's __mf_init() function existing in mf-runtime.c.
> Placing putenv(..) will limit the instrumented code's 
> runtime behaviour only to option being set in the code by me.

Well no, that would be silly - you might as well cut out the whole 
environment read entirely. Put it somewhere else - main perhaps.

If you don't want to do that, you still have the option of injecting the 
call via the debugger:

(gdb) break main
(gdb) continue
....
(gdb) call putenv("MUDFLAP_OPTIONS=<..>")
(gdb) continue

Of course, you have to have putenv linked into the program, but that can 
be arranged easily enough.

Andrew

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

* Re: Libmudflap for sh-elf toolchain cannot access environment variable MUDFLAP_OPTIONS
  2007-06-15 15:20 Deepen Mantri
@ 2007-06-15 15:28 ` Frank Ch. Eigler
  2007-06-15 15:32 ` Andrew STUBBS
  1 sibling, 0 replies; 7+ messages in thread
From: Frank Ch. Eigler @ 2007-06-15 15:28 UTC (permalink / raw)
  To: Deepen Mantri; +Cc: gcc

Hi -

> >It's probably easier to place a putenv("MUDFLAP_OPTIONS=blah")
> >in your code, or inject it from the debugger.
> 
> [...]
> We cannot place putenv("MUDFLAP_OPTIONS=<..>") in
> libmudflap's __mf_init() function existing in mf-runtime.c.
> Placing putenv(..) will limit the instrumented code's 
> runtime behaviour only to option being set in the code by me.

What you are asking about is outside the scope of gcc.  You need to
teach your simulator to pass environment variables on, or need to find
another way.

Since command line arguments are (sometimes) passed on, perhaps you
could write a short routine that parses MUDFLAP_OPTIONS from there and
calls __mf_set_options.

- FChE

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

* RE: Libmudflap for sh-elf toolchain cannot access environment variable MUDFLAP_OPTIONS
@ 2007-06-15 15:20 Deepen Mantri
  2007-06-15 15:28 ` Frank Ch. Eigler
  2007-06-15 15:32 ` Andrew STUBBS
  0 siblings, 2 replies; 7+ messages in thread
From: Deepen Mantri @ 2007-06-15 15:20 UTC (permalink / raw)
  To: Andrew STUBBS; +Cc: Frank Ch. Eigler, gcc



Andrew STUBBS wrote:
>It's probably easier to place a putenv("MUDFLAP_OPTIONS=blah")
>in your code, or inject it from the debugger.

Thanks for the reply.

MUDFLAP_OPTIONS environment variable is used to control the
run time behaviour of instrumented code generated with the 
help of libmudflap library.
There are about 30 options which user can set against this
environment variable and thus control the run-time behavior 
of the instrumented program. For details please refer the 
following link:
http://gcc.gnu.org/wiki/Mudflap_Pointer_Debugging 

We cannot place putenv("MUDFLAP_OPTIONS=<..>") in
libmudflap's __mf_init() function existing in mf-runtime.c.
Placing putenv(..) will limit the instrumented code's 
runtime behaviour only to option being set in the code by me.

Regards
Deepen Mantri
   
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Free download of GNU based tool-chains for Renesas' SH, H8,
R8C,M16C and M32C Series. The following site also offers free 
technical support to its users. 
Visit http://www.kpitgnutools.com for details.
Latest versions of KPIT GNU tools were released on Feb 6, 07
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

* Libmudflap for sh-elf toolchain cannot access environment variable MUDFLAP_OPTIONS
@ 2007-06-15 14:35 Deepen Mantri
  0 siblings, 0 replies; 7+ messages in thread
From: Deepen Mantri @ 2007-06-15 14:35 UTC (permalink / raw)
  To: Frank Ch. Eigler; +Cc: gcc




Hi,

I successfully built the sh-elf cross compiler on the
x86/linux host enabled with libmudflap by specifying the 
correct entry point in libmudflap's configure file.
(newlib-1.15.0 was used)  
 
I compiled a simple c code with following options on 
linux shell:

sh-elf-gcc -fmudflap test.c -static -lmudflap -o test.out

Then I set the MUDFLAP_OPTIONS environment variable as 
-print-leaks and executed the generated test.out file on
the sh-elf simulator. Nothing got displayed.

Following code snippet from __mf_init() function present
in mf-runtime.c is causing problem:

/////////////////////////////////////////////////////
.
.
ov = getenv ("MUDFLAP_OPTIONS");
  if (ov)
    {
      int rc = __mfu_set_options (ov);
      if (rc < 0)
        {
          __mf_usage ();
          exit (1);
        }
    }

  /* Initialize to a non-zero description epoch. */
  __mf_describe_object (NULL);
.
.
/////////////////////////////////////////////////////

getenv("MUDFLAP_OPTIONS") function call returns NULL 
because __environ is pointing to null terminated pointer
array. Hence the options are not setting. 

How to make x86/linux shell's environment variable 
(MUDFLAP_OPTIONS) accessible to test.out while executing
it through the sh-elf simulator? 

  
Regards,
Deepen Mantri

KPIT Cummins InfoSystems Ltd.
Pune, India

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Free download of GNU based tool-chains for Renesas' SH,H8,
R8C, M16C and M32C Series. The following site also offers 
free technical support to its users. 
Visit http://www.kpitgnutools.com for details.
Latest versions of KPIT GNU tools were released on Feb 6, 07
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

end of thread, other threads:[~2007-06-15 16:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-15 10:37 Libmudflap for sh-elf toolchain cannot access environment variable MUDFLAP_OPTIONS Deepen Mantri
2007-06-15 11:01 ` Andrew STUBBS
2007-06-15 14:35 Deepen Mantri
2007-06-15 15:20 Deepen Mantri
2007-06-15 15:28 ` Frank Ch. Eigler
2007-06-15 15:32 ` Andrew STUBBS
2007-06-15 16:07 Deepen Mantri

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).