linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* source code transform
@ 2009-01-07 18:48 mosfet
  2009-01-07 19:03 ` Johannes Berg
  0 siblings, 1 reply; 7+ messages in thread
From: mosfet @ 2009-01-07 18:48 UTC (permalink / raw)
  To: linux-sparse

Hi,

I would like to know if sparse would be able to parse GCC source file to
add a comment in each function it encounters ?
For instance let's say I want to trace every function in c-parser.c :


static struct c_typespec
c_parser_enum_specifier (c_parser *parser)
{
...

}

in a first step I would like to modify source code like this :

static struct c_typespec
c_parser_enum_specifier (c_parser *parser)
{
 fprintf(stderr, "c-parser.c: c_parser_enum_specifier()\n");
...

}

is it possible with sparse ?



-- 
Vincent R.

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

* Re: source code transform
  2009-01-07 18:48 source code transform mosfet
@ 2009-01-07 19:03 ` Johannes Berg
  2009-01-08  7:52   ` Nicholas Mc Guire
  2009-01-08 23:45   ` Yoann Padioleau
  0 siblings, 2 replies; 7+ messages in thread
From: Johannes Berg @ 2009-01-07 19:03 UTC (permalink / raw)
  To: mosfet; +Cc: linux-sparse

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

On Wed, 2009-01-07 at 19:48 +0100, mosfet wrote:

> I would like to know if sparse would be able to parse GCC source file to
> add a comment in each function it encounters ?
> For instance let's say I want to trace every function in c-parser.c :
> 
> 
> static struct c_typespec
> c_parser_enum_specifier (c_parser *parser)
> {
> ...
> 
> }
> 
> in a first step I would like to modify source code like this :
> 
> static struct c_typespec
> c_parser_enum_specifier (c_parser *parser)
> {
>  fprintf(stderr, "c-parser.c: c_parser_enum_specifier()\n");
> ...
> 
> }
> 
> is it possible with sparse ?

Not sure, but spatch might be able to:

http://www.emn.fr/x-info/coccinelle/

johannes

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: source code transform
  2009-01-07 19:03 ` Johannes Berg
@ 2009-01-08  7:52   ` Nicholas Mc Guire
  2009-01-08 23:45   ` Yoann Padioleau
  1 sibling, 0 replies; 7+ messages in thread
From: Nicholas Mc Guire @ 2009-01-08  7:52 UTC (permalink / raw)
  To: Johannes Berg; +Cc: mosfet, linux-sparse

On Wed, 7 Jan 2009, Johannes Berg wrote:

> On Wed, 2009-01-07 at 19:48 +0100, mosfet wrote:
>
> > I would like to know if sparse would be able to parse GCC source file to
> > add a comment in each function it encounters ?
> > For instance let's say I want to trace every function in c-parser.c :
> >
> >
> > static struct c_typespec
> > c_parser_enum_specifier (c_parser *parser)
> > {
> > ...
> >
> > }
> >
> > in a first step I would like to modify source code like this :
> >
> > static struct c_typespec
> > c_parser_enum_specifier (c_parser *parser)
> > {
> >  fprintf(stderr, "c-parser.c: c_parser_enum_specifier()\n");
> > ...
> >
> > }
> >
> > is it possible with sparse ?
>
> Not sure, but spatch might be able to:
>
> http://www.emn.fr/x-info/coccinelle/
>
you also could achieve this with -finstrument_functions by prviding
a cyg_func_enter function that would print the address - you then woud
have to reverse map addresses to functions via output of nm I guess.

hofrat

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

* Re: source code transform
  2009-01-07 19:03 ` Johannes Berg
  2009-01-08  7:52   ` Nicholas Mc Guire
@ 2009-01-08 23:45   ` Yoann Padioleau
  2009-01-09  0:38     ` Harvey Harrison
  1 sibling, 1 reply; 7+ messages in thread
From: Yoann Padioleau @ 2009-01-08 23:45 UTC (permalink / raw)
  To: Johannes Berg; +Cc: mosfet, linux-sparse, Julia Lawall

Johannes Berg <johannes@sipsolutions.net> writes:

> On Wed, 2009-01-07 at 19:48 +0100, mosfet wrote:
>
>> I would like to know if sparse would be able to parse GCC source file to
>> add a comment in each function it encounters ?
>> For instance let's say I want to trace every function in c-parser.c :
>> 
>> 
>> static struct c_typespec
>> c_parser_enum_specifier (c_parser *parser)
>> {
>> ...
>> 
>> }
>> 
>> in a first step I would like to modify source code like this :
>> 
>> static struct c_typespec
>> c_parser_enum_specifier (c_parser *parser)
>> {
>>  fprintf(stderr, "c-parser.c: c_parser_enum_specifier()\n");
>> ...
>> 
>> }
>> 
>> is it possible with sparse ?
>
> Not sure, but spatch might be able to:
>
> http://www.emn.fr/x-info/coccinelle/

Yes it can. Just write this semantic patch: 

@@
identifier f;
@@

 f(...)
 { 
+ fprintf(stderr, "%s: %s()\n", __FILE__, __FUNCTION__);
 ...
 }


into a file such as instrument_tracing.cocci and then run spatch with 


 $ ./spatch -c instrument_tracing.cocci c-parser.c -o c-parser-instrumented.c



>
> johannes

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

* Re: source code transform
  2009-01-08 23:45   ` Yoann Padioleau
@ 2009-01-09  0:38     ` Harvey Harrison
  2009-01-09 17:06       ` Yoann Padioleau
  0 siblings, 1 reply; 7+ messages in thread
From: Harvey Harrison @ 2009-01-09  0:38 UTC (permalink / raw)
  To: Yoann Padioleau; +Cc: Johannes Berg, mosfet, linux-sparse, Julia Lawall

On Thu, 2009-01-08 at 17:45 -0600, Yoann Padioleau wrote:
> Johannes Berg <johannes@sipsolutions.net> writes:

> @@
> identifier f;
> @@
> 
>  f(...)
>  { 
> + fprintf(stderr, "%s: %s()\n", __FILE__, __FUNCTION__);
>  ...
>  }
> 

Personal pet-peeve, use __func__, not __FUNCTION__.

__func__ is C, __FUNCTION__ is a gcc-extension.

Cheers,

Harvey


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

* Re: source code transform
  2009-01-09  0:38     ` Harvey Harrison
@ 2009-01-09 17:06       ` Yoann Padioleau
  2009-01-31 23:37         ` H. Peter Anvin
  0 siblings, 1 reply; 7+ messages in thread
From: Yoann Padioleau @ 2009-01-09 17:06 UTC (permalink / raw)
  To: Harvey Harrison; +Cc: Yoann Padioleau, Johannes Berg, mosfet, linux-sparse

Harvey Harrison <harvey.harrison@gmail.com> writes:

> On Thu, 2009-01-08 at 17:45 -0600, Yoann Padioleau wrote:
>> Johannes Berg <johannes@sipsolutions.net> writes:
>
>> @@
>> identifier f;
>> @@
>> 
>>  f(...)
>>  { 
>> + fprintf(stderr, "%s: %s()\n", __FILE__, __FUNCTION__);
>>  ...
>>  }
>> 
>
> Personal pet-peeve, use __func__, not __FUNCTION__.
>
> __func__ is C, __FUNCTION__ is a gcc-extension.

Ok. Is there also a __file__, and __line__ ? If this
not the case then I would rather keep my __FUNCTION__, 
it's estetically more consistent.

>
> Cheers,
>
> Harvey

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

* Re: source code transform
  2009-01-09 17:06       ` Yoann Padioleau
@ 2009-01-31 23:37         ` H. Peter Anvin
  0 siblings, 0 replies; 7+ messages in thread
From: H. Peter Anvin @ 2009-01-31 23:37 UTC (permalink / raw)
  To: Yoann Padioleau; +Cc: Harvey Harrison, Johannes Berg, mosfet, linux-sparse

Yoann Padioleau wrote:
>>>
>> Personal pet-peeve, use __func__, not __FUNCTION__.
>>
>> __func__ is C, __FUNCTION__ is a gcc-extension.
> 
> Ok. Is there also a __file__, and __line__ ? If this
> not the case then I would rather keep my __FUNCTION__, 
> it's estetically more consistent.
>

No, it's not.  __FILE__ and __LINE__ are macros (handled by the
preprocessor), but __func__ is a compiler token.

	-hpa

-- 
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.


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

end of thread, other threads:[~2009-01-31 23:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-07 18:48 source code transform mosfet
2009-01-07 19:03 ` Johannes Berg
2009-01-08  7:52   ` Nicholas Mc Guire
2009-01-08 23:45   ` Yoann Padioleau
2009-01-09  0:38     ` Harvey Harrison
2009-01-09 17:06       ` Yoann Padioleau
2009-01-31 23:37         ` H. Peter Anvin

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 NNTP newsgroup(s).