public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [PATCH 1/2] gcc symbol database
       [not found] <CA+dUcj3G+MhuQSOQVo5H=wK7R8PQ0MSOdX_s0+xM_ZvXXJkCJQ@mail.gmail.com>
@ 2012-06-04 14:02 ` Dodji Seketeli
  2012-06-05  6:56   ` Yunfeng ZHANG
  0 siblings, 1 reply; 18+ messages in thread
From: Dodji Seketeli @ 2012-06-04 14:02 UTC (permalink / raw)
  To: Yunfeng ZHANG; +Cc: gcc-patches, Joseph S. Myers, Dave Korn, Tom Tromey

Hello YunFeng,

Thank you for taking the time to work on this.  I cannot accept or
deny your patches, but I thought I could maybe comment on some parts
of them.

First, IMHO, some of the new plugin events you are proposing to add to
libcpp seem to make sense, at least so that people can write
etags/ctags-like cross-reference tools like the one you are proposing.

For now, I will not comment on the choices you've made for the
cross-reference tool itself, even though they are interesting to see,
at least to understand why you need the libcpp events you are
proposing.

Thus, I'll start with the libcpp changes.

[...]

> diff -upr .pc/symdb_enhance_libcpp/libcpp/directives.c libcpp/directives.c

[...]

> @@ -492,6 +492,8 @@ _cpp_handle_directive (cpp_reader *pfile
>    else if (skip == 0)
>      _cpp_backup_tokens (pfile, 1);
> 
> +  if (pfile->cb.end_directive)
> +    pfile->cb.end_directive (pfile);

It seems to me that there are possibly several places where we handle
directives.  In those places, the function start_directive and
end_directive are called.  So IMHO, it would seems more appropriate
and maintainable to call pfile->cb.start_directive in the
start_directive function, and likewise, call pfile->cg.end_directive
in the end_directive function.

You would then remove the call below from _cpp_lex_token:

@@ -1886,6 +1889,8 @@ _cpp_lex_token (cpp_reader *pfile)
          handles the directive as normal.  */
           && pfile->state.parsing_args != 1)
         {
+          if (pfile->cb.start_directive)
+        pfile->cb.start_directive (pfile, result);
           if (_cpp_handle_directive (pfile, result->flags & PREV_WHITE))
         {
           if (pfile->directive_result.type == CPP_PADDING)

[...]


> +++ libcpp/include/cpplib.h    2012-05-25 14:56:56.745507332 +0800
> @@ -218,10 +218,10 @@ struct GTY(()) cpp_identifier {
>         node;
>  };
> 
> -/* A preprocessing token.  This has been carefully packed and should
> -   occupy 16 bytes on 32-bit hosts and 24 bytes on 64-bit hosts.  */
> +/* A preprocessing token. */
>  struct GTY(()) cpp_token {
>    source_location src_loc;    /* Location of first char of token.  */
> +  int file_offset;

Enlarging this struct that is *widely* used might not be accepted by
the maintainers, because of the memory toll it takes.  Or you'd need
to prove that you cannot do otherwise.

So why is this file_offset member needed?

From the rest of the patch, it looks like you are using it to store
the offset of the token, from the beginning of its line.  What is the
difference between that, and the column number of the token, as you
could get by calling linemap_expand_location on the src_loc of the
token, effectively doing away with this new file_offset member?  Note
that the linemap_expand_location call was introduced in 4.7.

[...]

> +++ libcpp/macro.c    2012-05-25 14:56:56.749508416 +0800
> @@ -1029,9 +1029,13 @@ enter_macro_context (cpp_reader *pfile,
>            if (pragma_buff)
>          _cpp_release_buff (pfile, pragma_buff);
> 
> +          if (pfile->cb.macro_end_arg)
> +        pfile->cb.macro_end_arg (pfile, true);

Presumably, if we reach this point, I believe it means there was no
argument to what seemed to be a function-like macro.  Was it?

Thus, I don't understand why calling this pfile->cb.macro_end_arg call
achieves.  Actually, I think I don't understand the meaning of that
event callback, to begin with.  I have read and re-read the comment
below:

> @@ -522,6 +522,24 @@ struct cpp_callbacks
>       be expanded.  */

[...]

> +  /* Called when a function-like macro stops collecting macro parameters,
> +   * cancel = true, macro expansion is canceled. */
> +  void (*macro_end_arg) (cpp_reader *, bool cancel);

and I don't understand why you need the information conveyed by this
macro_end_arg event.

Maybe if you put the call to macro_start_expand in this
enter_macro_context function only after we are sure we are going to
actually proceed with the expansion ....

>            return 0;
>          }

... here, then you wouldn't need the macro_end_arg at all.  Would that
make sense?

>        if (macro->paramc > 0)
>          replace_args (pfile, node, macro,
>                (macro_arg *) buff->base,
> @@ -2263,6 +2267,8 @@ cpp_get_token_1 (cpp_reader *pfile, sour
>        if (pfile->context->c.macro)
>          ++num_expanded_macros_counter;
>        _cpp_pop_context (pfile);
> +      if (pfile->cb.macro_end_expand)
> +        pfile->cb.macro_end_expand (pfile);

_cpp_pop_context is really the function that marks the end of a given
macro expansion, especially when the predicate in_macro_expansion_p
(introduced recently in trunk for gcc 4.8) returns true.

So IMHO, I seems more maintainable to move the call to
pfile->cb.macro_end_expand in _cpp_pop_context.

>        if (pfile->state.in_directive)
>          continue;
>        result = &pfile->avoid_paste;
> @@ -2321,8 +2327,14 @@ cpp_get_token_1 (cpp_reader *pfile, sour
>          }
>          }
>        else
> -        ret = enter_macro_context (pfile, node, result,
> -                       virt_loc);
> +          {
> +           if (pfile->cb.macro_start_expand)
> +         pfile->cb.macro_start_expand (pfile, result, node);
> +       ret = enter_macro_context (pfile, node, result, virt_loc);

IMHO, it's more maintainable to put the call to
pfile->cb.macro_start_expand inside enter_macro_context, as that is
the function that really triggers the macro expansion.

> +     if (ret == 0 && pfile->cb.macro_end_expand)
> +       /* macro expansion is canceled. */
> +       pfile->cb.macro_end_expand (pfile);
> +         }

Note that if you move the call to pfile->cb.macro_end_expand into the
_cpp_pop_context function as suggested earlier, you can just remove it
from here.

Thank you.

-- 
		Dodji

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

* Re: [PATCH 1/2] gcc symbol database
  2012-06-04 14:02 ` [PATCH 1/2] gcc symbol database Dodji Seketeli
@ 2012-06-05  6:56   ` Yunfeng ZHANG
  2012-06-21  7:48     ` Yunfeng ZHANG
  0 siblings, 1 reply; 18+ messages in thread
From: Yunfeng ZHANG @ 2012-06-05  6:56 UTC (permalink / raw)
  To: Dodji Seketeli; +Cc: gcc-patches, Joseph S. Myers, Dave Korn, Tom Tromey

To Dodji Seketeli:
Thanks, I will republish my libcpp patch later.

2012/6/4 Dodji Seketeli <dodji@redhat.com>:
> Hello YunFeng,
>
> Thank you for taking the time to work on this.  I cannot accept or
> deny your patches, but I thought I could maybe comment on some parts
> of them.
>
> First, IMHO, some of the new plugin events you are proposing to add to
> libcpp seem to make sense, at least so that people can write
> etags/ctags-like cross-reference tools like the one you are proposing.
>
> For now, I will not comment on the choices you've made for the
> cross-reference tool itself, even though they are interesting to see,
> at least to understand why you need the libcpp events you are
> proposing.
>
> Thus, I'll start with the libcpp changes.
>
> [...]
>
>> diff -upr .pc/symdb_enhance_libcpp/libcpp/directives.c libcpp/directives.c
>
> [...]
>
>> @@ -492,6 +492,8 @@ _cpp_handle_directive (cpp_reader *pfile
>>    else if (skip == 0)
>>      _cpp_backup_tokens (pfile, 1);
>>
>> +  if (pfile->cb.end_directive)
>> +    pfile->cb.end_directive (pfile);
>
> It seems to me that there are possibly several places where we handle
> directives.  In those places, the function start_directive and
> end_directive are called.  So IMHO, it would seems more appropriate
> and maintainable to call pfile->cb.start_directive in the
> start_directive function, and likewise, call pfile->cg.end_directive
> in the end_directive function.
>
> You would then remove the call below from _cpp_lex_token:
>
> @@ -1886,6 +1889,8 @@ _cpp_lex_token (cpp_reader *pfile)
>          handles the directive as normal.  */
>           && pfile->state.parsing_args != 1)
>         {
> +          if (pfile->cb.start_directive)
> +        pfile->cb.start_directive (pfile, result);
>           if (_cpp_handle_directive (pfile, result->flags & PREV_WHITE))
>         {
>           if (pfile->directive_result.type == CPP_PADDING)
>
> [...]
>
>
>> +++ libcpp/include/cpplib.h    2012-05-25 14:56:56.745507332 +0800
>> @@ -218,10 +218,10 @@ struct GTY(()) cpp_identifier {
>>         node;
>>  };
>>
>> -/* A preprocessing token.  This has been carefully packed and should
>> -   occupy 16 bytes on 32-bit hosts and 24 bytes on 64-bit hosts.  */
>> +/* A preprocessing token. */
>>  struct GTY(()) cpp_token {
>>    source_location src_loc;    /* Location of first char of token.  */
>> +  int file_offset;
>
> Enlarging this struct that is *widely* used might not be accepted by
> the maintainers, because of the memory toll it takes.  Or you'd need
> to prove that you cannot do otherwise.
>
> So why is this file_offset member needed?
>
> From the rest of the patch, it looks like you are using it to store
> the offset of the token, from the beginning of its line.  What is the
> difference between that, and the column number of the token, as you
> could get by calling linemap_expand_location on the src_loc of the
> token, effectively doing away with this new file_offset member?  Note
> that the linemap_expand_location call was introduced in 4.7.
>
> [...]
>
>> +++ libcpp/macro.c    2012-05-25 14:56:56.749508416 +0800
>> @@ -1029,9 +1029,13 @@ enter_macro_context (cpp_reader *pfile,
>>            if (pragma_buff)
>>          _cpp_release_buff (pfile, pragma_buff);
>>
>> +          if (pfile->cb.macro_end_arg)
>> +        pfile->cb.macro_end_arg (pfile, true);
>
> Presumably, if we reach this point, I believe it means there was no
> argument to what seemed to be a function-like macro.  Was it?
>
> Thus, I don't understand why calling this pfile->cb.macro_end_arg call
> achieves.  Actually, I think I don't understand the meaning of that
> event callback, to begin with.  I have read and re-read the comment
> below:
>
>> @@ -522,6 +522,24 @@ struct cpp_callbacks
>>       be expanded.  */
>
> [...]
>
>> +  /* Called when a function-like macro stops collecting macro parameters,
>> +   * cancel = true, macro expansion is canceled. */
>> +  void (*macro_end_arg) (cpp_reader *, bool cancel);
>
> and I don't understand why you need the information conveyed by this
> macro_end_arg event.
>
> Maybe if you put the call to macro_start_expand in this
> enter_macro_context function only after we are sure we are going to
> actually proceed with the expansion ....
>
>>            return 0;
>>          }
>
> ... here, then you wouldn't need the macro_end_arg at all.  Would that
> make sense?
>
>>        if (macro->paramc > 0)
>>          replace_args (pfile, node, macro,
>>                (macro_arg *) buff->base,
>> @@ -2263,6 +2267,8 @@ cpp_get_token_1 (cpp_reader *pfile, sour
>>        if (pfile->context->c.macro)
>>          ++num_expanded_macros_counter;
>>        _cpp_pop_context (pfile);
>> +      if (pfile->cb.macro_end_expand)
>> +        pfile->cb.macro_end_expand (pfile);
>
> _cpp_pop_context is really the function that marks the end of a given
> macro expansion, especially when the predicate in_macro_expansion_p
> (introduced recently in trunk for gcc 4.8) returns true.
>
> So IMHO, I seems more maintainable to move the call to
> pfile->cb.macro_end_expand in _cpp_pop_context.
>
>>        if (pfile->state.in_directive)
>>          continue;
>>        result = &pfile->avoid_paste;
>> @@ -2321,8 +2327,14 @@ cpp_get_token_1 (cpp_reader *pfile, sour
>>          }
>>          }
>>        else
>> -        ret = enter_macro_context (pfile, node, result,
>> -                       virt_loc);
>> +          {
>> +           if (pfile->cb.macro_start_expand)
>> +         pfile->cb.macro_start_expand (pfile, result, node);
>> +       ret = enter_macro_context (pfile, node, result, virt_loc);
>
> IMHO, it's more maintainable to put the call to
> pfile->cb.macro_start_expand inside enter_macro_context, as that is
> the function that really triggers the macro expansion.
>
>> +     if (ret == 0 && pfile->cb.macro_end_expand)
>> +       /* macro expansion is canceled. */
>> +       pfile->cb.macro_end_expand (pfile);
>> +         }
>
> Note that if you move the call to pfile->cb.macro_end_expand into the
> _cpp_pop_context function as suggested earlier, you can just remove it
> from here.
>
> Thank you.
>
> --
>                Dodji

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

* Re: [PATCH 1/2] gcc symbol database
  2012-06-05  6:56   ` Yunfeng ZHANG
@ 2012-06-21  7:48     ` Yunfeng ZHANG
  2012-06-27  8:46       ` Yunfeng ZHANG
  2012-07-13 19:32       ` Dodji Seketeli
  0 siblings, 2 replies; 18+ messages in thread
From: Yunfeng ZHANG @ 2012-06-21  7:48 UTC (permalink / raw)
  To: Dodji Seketeli; +Cc: gcc-patches, Joseph S. Myers, Dave Korn, Tom Tromey

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

To Dodji Seketeli:

I'm sorry recent weeks I've got busy and my plugin is also found a bug when
compiling qemu, the bug is linking to cascaded case and should be fixed in
the attachment on gcc-4.7.1.

Later is the response from previous mail.
-------------------------
macro_end_expand can't be moved to _cpp_pop_context. My plugin shows later
results when `Gs callee _cpp_pop_context'.
	GS multiple definition:
	1)libcpp/directives.c 8130 skip_rest_of_line DEF_FUNC
	2)libcpp/macro.c 67161 expand_arg DEF_FUNC
	3)libcpp/macro.c 72900 cpp_get_token_1 DEF_FUNC
	4)libcpp/traditional.c 10560 _cpp_scan_out_logical_line DEF_FUNC
So macro_start_expand can't be moved to enter_macro_context since the pair
should be matched in the same function cpp_get_token_1.

1) macro_start_expand and macro_end_arg are used to tag all macro tokens.
2) macro_end_arg and macro_end_expand are used to tag all macro-replacement
tokens.
Tag the tokens are important to my plugin. So macro_start_expand can't be
moved to enter_macro_context when I'm sure a macro expansion has occured.

To make potential user free resource, macro_end_expand is called even macro is
canceled. That's why macro_end_expand is called twice in cpp_get_token_1.

If gcc can't accept cpp_token::file_offset field, I can change my plugin
stores token linenum other than token file_offset to database, final user
should be tolerate with it. Another solution is just like I have done --
compile an independ gcc for symdb only. In 471.tgz, I separate
cpp_token::file_offset to gcc.patches/symdb_negotiate_fileoffset.

I've attached all new patches on gcc side and ChangeLog, please check it.

By the way, have you tried my plugin in previous mail? Is there any problem?

Sincerely
																 Yunfeng Zhang

[-- Attachment #2: ChangeLog --]
[-- Type: application/octet-stream, Size: 1688 bytes --]

ChangeLog
-------------------------
libcpp/
2012-05-24  Yunfeng ZHANG <zyf.zeroos@gmail.com>

      * include/cpplib.h (struct cpp_callbacks): Add new callbacks.
      macro_start_expand, macro_end_arg, macro_end_expand, start_directive,
      end_directive, lex_token.
      * directives.c (start_directive): Implement start_directive.
      (end_directive): Implement end_directive.
      * macro.c (enter_macro_context): Implement macro_end_arg.
      (cpp_get_token_1): Implement macro_start_expand and macro_end_expand.
      * lex.c (_cpp_lex_token): Implement lex_token.

gcc/
2012-05-24  Yunfeng ZHANG <zyf.zeroos@gmail.com>

     * plugin.def: New plugin events, from new cpp/c token is arrived to new
     definition notification.
     * c-parser.c: Move c_id_kind/c_token definitions to c-family/c-common.h.
     (c_lex_one_token): Invoke PLUGIN_C_TOKEN callback.
     (c_parser_external_declaration): Invoke PLUGIN_EXTERN_DECL callback.
     (c_parser_declaration_or_fndef): Invoke PLUGIN_EXTERN_DECLSPECS,
     PLUGIN_EXTERN_VAR, PLUGIN_EXTERN_FUNC_OLD_PARAM, PLUGIN_EXTERN_FUNC
     callbacks.
     (c_parser_enum_specifier): Invoke PLUGIN_ENUM_SPECIFIER callback.
     (c_parser_postfix_expression_after_primary): Invoke PLUGIN_CALL_FUNCTION
     callback.
     * plugin.c (register_callback): Handle new plugin events.
     (invoke_plugin_callbacks_full): Likewise.
     * doc/plugins.texi: Document new plugin events.

gcc/c-family/
2012-05-24  Yunfeng ZHANG <zyf.zeroos@gmail.com>
     * c-lex.c: Include plugin.h.
     (c_lex_with_flags): Invoke PLUGIN_CPP_TOKEN callback.
     * c-common.h: Include c-pragma.h. Move c_id_kind/c_token definitions from
     c-parser.c.

[-- Attachment #3: libcpp.patch --]
[-- Type: application/octet-stream, Size: 5198 bytes --]

Only in libcpp/: ChangeLog
Only in libcpp/: Makefile.in
Only in libcpp/: aclocal.m4
Only in libcpp/: charset.c
Only in libcpp/: config.in
Only in libcpp/: configure
Only in libcpp/: configure.ac
Only in libcpp/: directives-only.c
diff -cpr .pc/symdb_enhance_libcpp/libcpp/directives.c libcpp/directives.c
*** .pc/symdb_enhance_libcpp/libcpp/directives.c	Wed Jun 20 09:09:15 2012
--- libcpp/directives.c	Wed Jun 20 09:20:28 2012
*************** start_directive (cpp_reader *pfile)
*** 275,280 ****
--- 275,283 ----
  
    /* Some handlers need the position of the # for diagnostics.  */
    pfile->directive_line = pfile->line_table->highest_line;
+ 
+   if (pfile->cb.start_directive)
+     pfile->cb.start_directive (pfile);
  }
  
  /* Called when leaving a directive, _Pragma or command-line directive.  */
*************** end_directive (cpp_reader *pfile, int sk
*** 309,314 ****
--- 312,320 ----
    pfile->state.in_expression = 0;
    pfile->state.angled_headers = 0;
    pfile->directive = 0;
+ 
+   if (pfile->cb.end_directive)
+     pfile->cb.end_directive (pfile);
  }
  
  /* Prepare to handle the directive in pfile->directive.  */
Only in libcpp/: errors.c
Only in libcpp/: expr.c
Only in libcpp/: files.c
Only in libcpp/: identifiers.c
Only in libcpp/include: cpp-id-data.h
diff -cpr .pc/symdb_enhance_libcpp/libcpp/include/cpplib.h libcpp/include/cpplib.h
*** .pc/symdb_enhance_libcpp/libcpp/include/cpplib.h	Wed Jun 20 09:09:15 2012
--- libcpp/include/cpplib.h	Wed Jun 20 09:22:34 2012
*************** struct cpp_callbacks
*** 522,527 ****
--- 522,542 ----
       be expanded.  */
    cpp_hashnode * (*macro_to_expand) (cpp_reader *, const cpp_token *);
  
+   /* macro_{start/end}_expand are called when gcc starts to expand macro, note
+    * if A macro includes B macro, the pair is called multiple times. */
+   void (*macro_start_expand) (cpp_reader *, const cpp_token *,
+ 		  const cpp_hashnode *);
+   void (*macro_end_expand) (cpp_reader *);
+   /* Called when a function-like macro stops collecting macro parameters,
+    * cancel = true, macro expansion is canceled. */
+   void (*macro_end_arg) (cpp_reader *, bool cancel);
+   /* The pair is called when cpp directive (starting from `#', such as
+    * `#define', `#endif' etc) is encountered and reaches end. */
+   void (*start_directive) (cpp_reader *);
+   void (*end_directive) (cpp_reader *);
+   /* The more powerful function getting token than cpp_get_token. */
+   void (*lex_token) (cpp_reader *, const cpp_token*);
+ 
    /* Called to emit a diagnostic.  This callback receives the
       translated message.  */
    bool (*error) (cpp_reader *, int, int, source_location, unsigned int,
Only in libcpp/include: line-map.h
Only in libcpp/include: mkdeps.h
Only in libcpp/include: symtab.h
Only in libcpp/: init.c
Only in libcpp/: internal.h
diff -cpr .pc/symdb_enhance_libcpp/libcpp/lex.c libcpp/lex.c
*** .pc/symdb_enhance_libcpp/libcpp/lex.c	Wed Jun 20 09:09:15 2012
--- libcpp/lex.c	Wed Jun 20 09:20:28 2012
*************** _cpp_lex_token (cpp_reader *pfile)
*** 1875,1880 ****
--- 1875,1882 ----
  	}
        else
  	result = _cpp_lex_direct (pfile);
+     if (pfile->cb.lex_token)
+       pfile->cb.lex_token (pfile, result);
  
        if (result->flags & BOL)
  	{
Only in libcpp/: line-map.c
diff -cpr .pc/symdb_enhance_libcpp/libcpp/macro.c libcpp/macro.c
*** .pc/symdb_enhance_libcpp/libcpp/macro.c	Wed Jun 20 09:09:15 2012
--- libcpp/macro.c	Wed Jun 20 09:20:28 2012
*************** enter_macro_context (cpp_reader *pfile, 
*** 1015,1020 ****
--- 1015,1022 ----
  	  pfile->state.parsing_args = 1;
  	  buff = funlike_invocation_p (pfile, node, &pragma_buff,
  				       &num_args);
+ 	  if (pfile->cb.macro_end_arg)
+ 	    pfile->cb.macro_end_arg (pfile, buff == NULL);
  	  pfile->state.parsing_args = 0;
  	  pfile->keep_tokens--;
  	  pfile->state.prevent_expansion--;
*************** cpp_get_token_1 (cpp_reader *pfile, sour
*** 2263,2268 ****
--- 2265,2272 ----
  	  if (pfile->context->c.macro)
  	    ++num_expanded_macros_counter;
  	  _cpp_pop_context (pfile);
+ 	  if (pfile->cb.macro_end_expand)
+ 	    pfile->cb.macro_end_expand (pfile);
  	  if (pfile->state.in_directive)
  	    continue;
  	  result = &pfile->avoid_paste;
*************** cpp_get_token_1 (cpp_reader *pfile, sour
*** 2321,2328 ****
  		}
  	    }
  	  else
! 	    ret = enter_macro_context (pfile, node, result, 
! 				       virt_loc);
  	  if (ret)
   	    {
  	      if (pfile->state.in_directive || ret == 2)
--- 2325,2338 ----
  		}
  	    }
  	  else
!  	    {
! 	      if (pfile->cb.macro_start_expand)
! 		pfile->cb.macro_start_expand (pfile, result, node);
! 	  ret = enter_macro_context (pfile, node, result, virt_loc);
!     if (ret == 0 && pfile->cb.macro_end_expand)
!       /* macro expansion is canceled. */
!       pfile->cb.macro_end_expand (pfile);
! 	    }
  	  if (ret)
   	    {
  	      if (pfile->state.in_directive || ret == 2)
Only in libcpp/: macro.c.rej
Only in libcpp/: makeucnid.c
Only in libcpp/: mkdeps.c
Only in libcpp/: pch.c
Only in libcpp/: po
Only in libcpp/: symtab.c
Only in libcpp/: system.h
Only in libcpp/: traditional.c
Only in libcpp/: ucnid.h
Only in libcpp/: ucnid.tab

[-- Attachment #4: plugin.patch --]
[-- Type: application/octet-stream, Size: 32938 bytes --]

Only in gcc/: ABOUT-GCC-NLS
Only in gcc/: BASE-VER
Only in gcc/: COPYING
Only in gcc/: COPYING.LIB
Only in gcc/: COPYING3
Only in gcc/: COPYING3.LIB
Only in gcc/: ChangeLog
Only in gcc/: ChangeLog-1997
Only in gcc/: ChangeLog-1998
Only in gcc/: ChangeLog-1999
Only in gcc/: ChangeLog-2000
Only in gcc/: ChangeLog-2001
Only in gcc/: ChangeLog-2002
Only in gcc/: ChangeLog-2003
Only in gcc/: ChangeLog-2004
Only in gcc/: ChangeLog-2005
Only in gcc/: ChangeLog-2006
Only in gcc/: ChangeLog-2007
Only in gcc/: ChangeLog-2008
Only in gcc/: ChangeLog-2009
Only in gcc/: ChangeLog-2010
Only in gcc/: ChangeLog-2011
Only in gcc/: ChangeLog.dataflow
Only in gcc/: ChangeLog.graphite
Only in gcc/: ChangeLog.lib
Only in gcc/: ChangeLog.ptr
Only in gcc/: ChangeLog.tree-ssa
Only in gcc/: ChangeLog.tuples
Only in gcc/: DATESTAMP
Only in gcc/: DEV-PHASE
Only in gcc/: FSFChangeLog
Only in gcc/: FSFChangeLog.10
Only in gcc/: FSFChangeLog.11
Only in gcc/: LANGUAGES
Only in gcc/: Makefile.in
Only in gcc/: ONEWS
Only in gcc/: README.Portability
Only in gcc/: acinclude.m4
Only in gcc/: aclocal.m4
Only in gcc/: ada
Only in gcc/: addresses.h
Only in gcc/: alias.c
Only in gcc/: alias.h
Only in gcc/: alloc-pool.c
Only in gcc/: alloc-pool.h
Only in gcc/: attribs.c
Only in gcc/: auto-inc-dec.c
Only in gcc/: basic-block.h
Only in gcc/: bb-reorder.c
Only in gcc/: bb-reorder.h
Only in gcc/: bitmap.c
Only in gcc/: bitmap.h
Only in gcc/: bt-load.c
Only in gcc/: builtin-attrs.def
Only in gcc/: builtin-types.def
Only in gcc/: builtins.c
Only in gcc/: builtins.def
Only in gcc/: builtins.h
Only in gcc/: c-aux-info.c
Only in gcc/: c-config-lang.in
Only in gcc/: c-convert.c
Only in gcc/: c-decl.c
Only in gcc/: c-errors.c
Only in gcc/c-family: ChangeLog
Only in gcc/c-family: c-ada-spec.c
Only in gcc/c-family: c-ada-spec.h
Only in gcc/c-family: c-common.c
Only in gcc/c-family: c-common.def
diff -cpr .pc/symdb_enhance_plugin/gcc/c-family/c-common.h gcc/c-family/c-common.h
*** .pc/symdb_enhance_plugin/gcc/c-family/c-common.h	Wed Jun 20 09:09:15 2012
--- gcc/c-family/c-common.h	Wed Jun 20 09:43:23 2012
*************** along with GCC; see the file COPYING3.  
*** 25,30 ****
--- 25,31 ----
  #include "splay-tree.h"
  #include "cpplib.h"
  #include "ggc.h"
+ #include "c-pragma.h"
  
  /* In order for the format checking to accept the C frontend
     diagnostic framework extensions, you must include this file before
*************** extern bool c_omp_sharing_predetermined 
*** 1056,1061 ****
--- 1057,1101 ----
  extern tree c_omp_remap_decl (tree, bool);
  extern void record_types_used_by_current_var_decl (tree);
  
+ /* The following local token type is used.  */
+ 
+ /* A keyword.  */
+ #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
+ 
+ /* More information about the type of a CPP_NAME token.  */
+ typedef enum c_id_kind {
+   /* An ordinary identifier.  */
+   C_ID_ID,
+   /* An identifier declared as a typedef name.  */
+   C_ID_TYPENAME,
+   /* An identifier declared as an Objective-C class name.  */
+   C_ID_CLASSNAME,
+   /* An address space identifier.  */
+   C_ID_ADDRSPACE,
+   /* Not an identifier.  */
+   C_ID_NONE
+ } c_id_kind;
+ 
+ /* A single C token after string literal concatenation and conversion
+    of preprocessing tokens to tokens.  */
+ typedef struct GTY (()) c_token {
+   /* The kind of token.  */
+   ENUM_BITFIELD (cpp_ttype) type : 8;
+   /* If this token is a CPP_NAME, this value indicates whether also
+      declared as some kind of type.  Otherwise, it is C_ID_NONE.  */
+   ENUM_BITFIELD (c_id_kind) id_kind : 8;
+   /* If this token is a keyword, this value indicates which keyword.
+      Otherwise, this value is RID_MAX.  */
+   ENUM_BITFIELD (rid) keyword : 8;
+   /* If this token is a CPP_PRAGMA, this indicates the pragma that
+      was seen.  Otherwise it is PRAGMA_NONE.  */
+   ENUM_BITFIELD (pragma_kind) pragma_kind : 8;
+   /* The value associated with this token, if any.  */
+   tree value;
+   /* The location at which this token was found.  */
+   location_t location;
+ } c_token;
+ 
  /* Return next tree in the chain for chain_next walking of tree nodes.  */
  static inline tree
  c_tree_chain_next (tree t)
Only in gcc/c-family: c-cppbuiltin.c
Only in gcc/c-family: c-dump.c
Only in gcc/c-family: c-format.c
Only in gcc/c-family: c-format.h
Only in gcc/c-family: c-gimplify.c
diff -cpr .pc/symdb_enhance_plugin/gcc/c-family/c-lex.c gcc/c-family/c-lex.c
*** .pc/symdb_enhance_plugin/gcc/c-family/c-lex.c	Wed Jun 20 09:09:15 2012
--- gcc/c-family/c-lex.c	Wed Jun 20 09:43:02 2012
*************** along with GCC; see the file COPYING3.  
*** 36,41 ****
--- 36,42 ----
  #include "splay-tree.h"
  #include "debug.h"
  #include "target.h"
+ #include "plugin.h"
  
  /* We may keep statistics about how long which files took to compile.  */
  static int header_time, body_time;
*************** c_lex_with_flags (tree *value, location_
*** 382,387 ****
--- 383,389 ----
  	    case CPP_STRING32:
  	    case CPP_UTF8STRING:
  	      type = lex_string (tok, value, true, true);
+ 		  tok = NULL;
  	      break;
  
  	    case CPP_NAME:
*************** c_lex_with_flags (tree *value, location_
*** 483,488 ****
--- 485,491 ----
  	{
  	  type = lex_string (tok, value, false,
  			     (lex_flags & C_LEX_STRING_NO_TRANSLATE) == 0);
+ 	  tok = NULL;
  	  break;
  	}
        *value = build_string (tok->val.str.len, (const char *) tok->val.str.text);
*************** c_lex_with_flags (tree *value, location_
*** 517,522 ****
--- 520,526 ----
      }
  
    timevar_pop (TV_CPP);
+   invoke_plugin_callbacks (PLUGIN_CPP_TOKEN, tok);
  
    return type;
  }
Only in gcc/c-family: c-objc.h
Only in gcc/c-family: c-omp.c
Only in gcc/c-family: c-opts.c
Only in gcc/c-family: c-pch.c
Only in gcc/c-family: c-ppoutput.c
Only in gcc/c-family: c-pragma.c
Only in gcc/c-family: c-pragma.h
Only in gcc/c-family: c-pretty-print.c
Only in gcc/c-family: c-pretty-print.h
Only in gcc/c-family: c-semantics.c
Only in gcc/c-family: c-target-def.h
Only in gcc/c-family: c-target.def
Only in gcc/c-family: c-target.h
Only in gcc/c-family: c.opt
Only in gcc/c-family: stub-objc.c
Only in gcc/: c-lang.c
Only in gcc/: c-lang.h
Only in gcc/: c-objc-common.c
Only in gcc/: c-objc-common.h
diff -cpr .pc/symdb_enhance_plugin/gcc/c-parser.c gcc/c-parser.c
*** .pc/symdb_enhance_plugin/gcc/c-parser.c	Wed Jun 20 09:09:15 2012
--- gcc/c-parser.c	Wed Jun 20 09:35:20 2012
*************** c_parse_init (void)
*** 121,165 ****
     C++).  It would then be possible to share more of the C and C++
     lexer code, if desired.  */
  
- /* The following local token type is used.  */
- 
- /* A keyword.  */
- #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
- 
- /* More information about the type of a CPP_NAME token.  */
- typedef enum c_id_kind {
-   /* An ordinary identifier.  */
-   C_ID_ID,
-   /* An identifier declared as a typedef name.  */
-   C_ID_TYPENAME,
-   /* An identifier declared as an Objective-C class name.  */
-   C_ID_CLASSNAME,
-   /* An address space identifier.  */
-   C_ID_ADDRSPACE,
-   /* Not an identifier.  */
-   C_ID_NONE
- } c_id_kind;
- 
- /* A single C token after string literal concatenation and conversion
-    of preprocessing tokens to tokens.  */
- typedef struct GTY (()) c_token {
-   /* The kind of token.  */
-   ENUM_BITFIELD (cpp_ttype) type : 8;
-   /* If this token is a CPP_NAME, this value indicates whether also
-      declared as some kind of type.  Otherwise, it is C_ID_NONE.  */
-   ENUM_BITFIELD (c_id_kind) id_kind : 8;
-   /* If this token is a keyword, this value indicates which keyword.
-      Otherwise, this value is RID_MAX.  */
-   ENUM_BITFIELD (rid) keyword : 8;
-   /* If this token is a CPP_PRAGMA, this indicates the pragma that
-      was seen.  Otherwise it is PRAGMA_NONE.  */
-   ENUM_BITFIELD (pragma_kind) pragma_kind : 8;
-   /* The location at which this token was found.  */
-   location_t location;
-   /* The value associated with this token, if any.  */
-   tree value;
- } c_token;
- 
  /* A parser structure recording information about the state and
     context of parsing.  Includes lexer information with up to two
     tokens of look-ahead; more are not needed for C.  */
--- 121,126 ----
*************** c_lex_one_token (c_parser *parser, c_tok
*** 388,393 ****
--- 349,355 ----
        break;
      }
    timevar_pop (TV_LEX);
+   invoke_plugin_callbacks (PLUGIN_C_TOKEN, token);
  }
  
  /* Return a pointer to the next token from PARSER, reading it in if
*************** c_parser_external_declaration (c_parser 
*** 1360,1365 ****
--- 1322,1328 ----
  	 an @interface or @protocol with prefix attributes).  We can
  	 only tell which after parsing the declaration specifiers, if
  	 any, and the first declarator.  */
+       invoke_plugin_callbacks (PLUGIN_EXTERN_DECL, NULL);
        c_parser_declaration_or_fndef (parser, true, true, true, false, true, NULL);
        break;
      }
*************** c_parser_declaration_or_fndef (c_parser 
*** 1488,1493 ****
--- 1451,1461 ----
        return;
      }
    finish_declspecs (specs);
+   {
+     void* pair[2]; pair[0] = specs; pair[1] = (void*) parser->tokens_avail;
+     if (!nested)
+       invoke_plugin_callbacks (PLUGIN_EXTERN_DECLSPECS, pair);
+   }
    if (c_parser_next_token_is (parser, CPP_SEMICOLON))
      {
        if (empty_ok)
*************** c_parser_declaration_or_fndef (c_parser 
*** 1622,1627 ****
--- 1590,1600 ----
  	{
  	  tree asm_name = NULL_TREE;
  	  tree postfix_attrs = NULL_TREE;
+ 	  {
+ 	    void* pair[2]; pair[0] = specs; pair[1] = declarator;
+         if (!nested)
+           invoke_plugin_callbacks (PLUGIN_EXTERN_VAR, pair);
+ 	  }
  	  if (!diagnosed_no_specs && !specs->declspecs_seen_p)
  	    {
  	      diagnosed_no_specs = true;
*************** c_parser_declaration_or_fndef (c_parser 
*** 1748,1758 ****
--- 1721,1735 ----
  	 declarator with a nonempty identifier list in a definition;
  	 and postfix attributes have never been accepted here in
  	 function definitions either.  */
+       if (!nested)
+         invoke_plugin_callbacks (PLUGIN_EXTERN_FUNC_OLD_PARAM, NULL);
        while (c_parser_next_token_is_not (parser, CPP_EOF)
  	     && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
  	c_parser_declaration_or_fndef (parser, false, false, false,
  				       true, false, NULL);
        store_parm_decls ();
+       if (!nested)
+         invoke_plugin_callbacks (PLUGIN_EXTERN_FUNC, declarator);
        DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
  	= c_parser_peek_token (parser)->location;
        fnbody = c_parser_compound_statement (parser);
*************** c_parser_enum_specifier (c_parser *parse
*** 2266,2271 ****
--- 2243,2249 ----
  	    }
  	  token = c_parser_peek_token (parser);
  	  enum_id = token->value;
+       invoke_plugin_callbacks (PLUGIN_ENUMERATOR, enum_id);
  	  /* Set the location in case we create a decl now.  */
  	  c_parser_set_source_position_from_token (token);
  	  decl_loc = value_loc = token->location;
*************** c_parser_postfix_expression_after_primar
*** 6870,6875 ****
--- 6848,6854 ----
  	  break;
  	case CPP_OPEN_PAREN:
  	  /* Function call.  */
+       invoke_plugin_callbacks (PLUGIN_CALL_FUNCTION, expr.value);
  	  c_parser_consume_token (parser);
  	  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
  	    exprlist = NULL;
Only in gcc/: c-tree.h
Only in gcc/: c-typeck.c
Only in gcc/: caller-save.c
Only in gcc/: calls.c
Only in gcc/: cfg.c
Only in gcc/: cfganal.c
Only in gcc/: cfgbuild.c
Only in gcc/: cfgcleanup.c
Only in gcc/: cfgexpand.c
Only in gcc/: cfghooks.c
Only in gcc/: cfghooks.h
Only in gcc/: cfglayout.c
Only in gcc/: cfglayout.h
Only in gcc/: cfgloop.c
Only in gcc/: cfgloop.h
Only in gcc/: cfgloopanal.c
Only in gcc/: cfgloopmanip.c
Only in gcc/: cfgrtl.c
Only in gcc/: cgraph.c
Only in gcc/: cgraph.h
Only in gcc/: cgraphbuild.c
Only in gcc/: cgraphunit.c
Only in gcc/: cif-code.def
Only in gcc/: collect2-aix.c
Only in gcc/: collect2-aix.h
Only in gcc/: collect2.c
Only in gcc/: collect2.h
Only in gcc/: combine-stack-adj.c
Only in gcc/: combine.c
Only in gcc/: common
Only in gcc/: common.opt
Only in gcc/: compare-elim.c
Only in gcc/: conditions.h
Only in gcc/: config
Only in gcc/: config.build
Only in gcc/: config.gcc
Only in gcc/: config.host
Only in gcc/: config.in
Only in gcc/: configure
Only in gcc/: configure.ac
Only in gcc/: convert.c
Only in gcc/: convert.h
Only in gcc/: coretypes.h
Only in gcc/: coverage.c
Only in gcc/: coverage.h
Only in gcc/: cp
Only in gcc/: cppbuiltin.c
Only in gcc/: cppbuiltin.h
Only in gcc/: cppdefault.c
Only in gcc/: cppdefault.h
Only in gcc/: cppspec.c
Only in gcc/: cprop.c
Only in gcc/: cse.c
Only in gcc/: cselib.c
Only in gcc/: cselib.h
Only in gcc/: cstamp-h.in
Only in gcc/: data-streamer-in.c
Only in gcc/: data-streamer-out.c
Only in gcc/: data-streamer.c
Only in gcc/: data-streamer.h
Only in gcc/: dbgcnt.c
Only in gcc/: dbgcnt.def
Only in gcc/: dbgcnt.h
Only in gcc/: dbxout.c
Only in gcc/: dbxout.h
Only in gcc/: dce.c
Only in gcc/: dce.h
Only in gcc/: ddg.c
Only in gcc/: ddg.h
Only in gcc/: debug.c
Only in gcc/: debug.h
Only in gcc/: defaults.h
Only in gcc/: df-core.c
Only in gcc/: df-problems.c
Only in gcc/: df-scan.c
Only in gcc/: df.h
Only in gcc/: dfp.c
Only in gcc/: dfp.h
Only in gcc/: diagnostic-core.h
Only in gcc/: diagnostic.c
Only in gcc/: diagnostic.def
Only in gcc/: diagnostic.h
Only in gcc/doc: aot-compile.1
Only in gcc/doc: arm-neon-intrinsics.texi
Only in gcc/doc: bugreport.texi
Only in gcc/doc: cfg.texi
Only in gcc/doc: collect2.texi
Only in gcc/doc: compat.texi
Only in gcc/doc: configfiles.texi
Only in gcc/doc: configterms.texi
Only in gcc/doc: contrib.texi
Only in gcc/doc: contribute.texi
Only in gcc/doc: cpp.1
Only in gcc/doc: cpp.info
Only in gcc/doc: cpp.texi
Only in gcc/doc: cppenv.texi
Only in gcc/doc: cppinternals.info
Only in gcc/doc: cppinternals.texi
Only in gcc/doc: cppopts.texi
Only in gcc/doc: extend.texi
Only in gcc/doc: fragments.texi
Only in gcc/doc: frontends.texi
Only in gcc/doc: fsf-funding.7
Only in gcc/doc: g++.1
Only in gcc/doc: gc-analyze.1
Only in gcc/doc: gcc.1
Only in gcc/doc: gcc.info
Only in gcc/doc: gcc.texi
Only in gcc/doc: gccinstall.info
Only in gcc/doc: gccint.info
Only in gcc/doc: gccint.texi
Only in gcc/doc: gcj-dbtool.1
Only in gcc/doc: gcj.1
Only in gcc/doc: gcj.info
Only in gcc/doc: gcov.1
Only in gcc/doc: gcov.texi
Only in gcc/doc: generic.texi
Only in gcc/doc: gfdl.7
Only in gcc/doc: gfortran.1
Only in gcc/doc: gij.1
Only in gcc/doc: gimple.texi
Only in gcc/doc: gnu.texi
Only in gcc/doc: gpl.7
Only in gcc/doc: grmic.1
Only in gcc/doc: gty.texi
Only in gcc/doc: headerdirs.texi
Only in gcc/doc: hostconfig.texi
Only in gcc/doc: implement-c.texi
Only in gcc/doc: implement-cxx.texi
Only in gcc/doc: include
Only in gcc/doc: install-old.texi
Only in gcc/doc: install.texi
Only in gcc/doc: install.texi2html
Only in gcc/doc: interface.texi
Only in gcc/doc: invoke.texi
Only in gcc/doc: jcf-dump.1
Only in gcc/doc: jv-convert.1
Only in gcc/doc: languages.texi
Only in gcc/doc: libgcc.texi
Only in gcc/doc: loop.texi
Only in gcc/doc: lto.texi
Only in gcc/doc: makefile.texi
Only in gcc/doc: md.texi
Only in gcc/doc: objc.texi
Only in gcc/doc: options.texi
Only in gcc/doc: passes.texi
diff -cpr .pc/symdb_enhance_plugin/gcc/doc/plugins.texi gcc/doc/plugins.texi
*** .pc/symdb_enhance_plugin/gcc/doc/plugins.texi	Wed Jun 20 09:09:15 2012
--- gcc/doc/plugins.texi	Wed Jun 20 09:38:13 2012
*************** enum plugin_event
*** 184,189 ****
--- 184,206 ----
    PLUGIN_EARLY_GIMPLE_PASSES_END,
    /* Called when a pass is first instantiated.  */
    PLUGIN_NEW_PASS,
+   PLUGIN_CPP_TOKEN,                /* Called when GCC gets a cpp token. */
+   PLUGIN_C_TOKEN,                  /* Called when GCC gets a c token. */
+   /* An extern declaration (file-scope) is encounted. */
+   PLUGIN_EXTERN_DECL,
+   /* Cooperate PLUGIN_EXTERN_FUNC to parse a function with old-style parameter
+    * declaration. */
+   PLUGIN_EXTERN_FUNC_OLD_PARAM,
+   /* An extern function definition is parsed. */
+   PLUGIN_EXTERN_FUNC,
+   /* An extern variable definition is parsed. */
+   PLUGIN_EXTERN_VAR,
+   /* An extern declaration specifier definition is parsed. */
+   PLUGIN_EXTERN_DECLSPECS,
+   /* A function is called. */
+   PLUGIN_CALL_FUNCTION,
+   /* An enumerator is parsed. */
+   PLUGIN_ENUMERATOR,
  
    PLUGIN_EVENT_FIRST_DYNAMIC    /* Dummy event used for indexing callback
                                     array.  */
Only in gcc/doc: portability.texi
Only in gcc/doc: rebuild-gcj-db.1
Only in gcc/doc: rtl.texi
Only in gcc/doc: service.texi
Only in gcc/doc: sourcebuild.texi
Only in gcc/doc: standards.texi
Only in gcc/doc: tm.texi
Only in gcc/doc: tm.texi.in
Only in gcc/doc: tree-ssa.texi
Only in gcc/doc: trouble.texi
Only in gcc/: dojump.c
Only in gcc/: dominance.c
Only in gcc/: domwalk.c
Only in gcc/: domwalk.h
Only in gcc/: double-int.c
Only in gcc/: double-int.h
Only in gcc/: dse.c
Only in gcc/: dse.h
Only in gcc/: dwarf2asm.c
Only in gcc/: dwarf2asm.h
Only in gcc/: dwarf2cfi.c
Only in gcc/: dwarf2out.c
Only in gcc/: dwarf2out.h
Only in gcc/: ebitmap.c
Only in gcc/: ebitmap.h
Only in gcc/: emit-rtl.c
Only in gcc/: emit-rtl.h
Only in gcc/: errors.c
Only in gcc/: errors.h
Only in gcc/: et-forest.c
Only in gcc/: et-forest.h
Only in gcc/: except.c
Only in gcc/: except.h
Only in gcc/: exec-tool.in
Only in gcc/: explow.c
Only in gcc/: expmed.c
Only in gcc/: expmed.h
Only in gcc/: expr.c
Only in gcc/: expr.h
Only in gcc/: final.c
Only in gcc/: fixed-value.c
Only in gcc/: fixed-value.h
Only in gcc/: flag-types.h
Only in gcc/: flags.h
Only in gcc/: fold-const.c
Only in gcc/: fortran
Only in gcc/: fp-test.c
Only in gcc/: function.c
Only in gcc/: function.h
Only in gcc/: fwprop.c
Only in gcc/: gcc-ar.c
Only in gcc/: gcc-plugin.h
Only in gcc/: gcc.c
Only in gcc/: gcc.h
Only in gcc/: gccspec.c
Only in gcc/: gcov-dump.c
Only in gcc/: gcov-io.c
Only in gcc/: gcov-io.h
Only in gcc/: gcov-iov.c
Only in gcc/: gcov.c
Only in gcc/: gcse.c
Only in gcc/: gcse.h
Only in gcc/: gdbinit.in
Only in gcc/: genattr-common.c
Only in gcc/: genattr.c
Only in gcc/: genattrtab.c
Only in gcc/: genautomata.c
Only in gcc/: gencheck.c
Only in gcc/: genchecksum.c
Only in gcc/: gencodes.c
Only in gcc/: genconditions.c
Only in gcc/: genconfig.c
Only in gcc/: genconstants.c
Only in gcc/: genemit.c
Only in gcc/: genenums.c
Only in gcc/: genextract.c
Only in gcc/: genflags.c
Only in gcc/: gengenrtl.c
Only in gcc/: gengtype-lex.c
Only in gcc/: gengtype-lex.l
Only in gcc/: gengtype-parse.c
Only in gcc/: gengtype-state.c
Only in gcc/: gengtype.c
Only in gcc/: gengtype.h
Only in gcc/: genhooks.c
Only in gcc/: genmddeps.c
Only in gcc/: genmodes.c
Only in gcc/: genmultilib
Only in gcc/: genopinit.c
Only in gcc/: genoutput.c
Only in gcc/: genpeep.c
Only in gcc/: genpreds.c
Only in gcc/: genrecog.c
Only in gcc/: gensupport.c
Only in gcc/: gensupport.h
Only in gcc/: ggc-common.c
Only in gcc/: ggc-internal.h
Only in gcc/: ggc-none.c
Only in gcc/: ggc-page.c
Only in gcc/: ggc-zone.c
Only in gcc/: ggc.h
Only in gcc/: gimple-fold.c
Only in gcc/: gimple-fold.h
Only in gcc/: gimple-iterator.c
Only in gcc/: gimple-low.c
Only in gcc/: gimple-pretty-print.c
Only in gcc/: gimple-pretty-print.h
Only in gcc/: gimple-streamer-in.c
Only in gcc/: gimple-streamer-out.c
Only in gcc/: gimple-streamer.h
Only in gcc/: gimple.c
Only in gcc/: gimple.def
Only in gcc/: gimple.h
Only in gcc/: gimplify.c
Only in gcc/: ginclude
Only in gcc/: glimits.h
Only in gcc/: go
Only in gcc/: godump.c
Only in gcc/: graph.c
Only in gcc/: graph.h
Only in gcc/: graphds.c
Only in gcc/: graphds.h
Only in gcc/: graphite-blocking.c
Only in gcc/: graphite-clast-to-gimple.c
Only in gcc/: graphite-clast-to-gimple.h
Only in gcc/: graphite-cloog-compat.h
Only in gcc/: graphite-cloog-util.c
Only in gcc/: graphite-cloog-util.h
Only in gcc/: graphite-dependences.c
Only in gcc/: graphite-dependences.h
Only in gcc/: graphite-flattening.c
Only in gcc/: graphite-interchange.c
Only in gcc/: graphite-poly.c
Only in gcc/: graphite-poly.h
Only in gcc/: graphite-ppl.c
Only in gcc/: graphite-ppl.h
Only in gcc/: graphite-scop-detection.c
Only in gcc/: graphite-scop-detection.h
Only in gcc/: graphite-sese-to-poly.c
Only in gcc/: graphite-sese-to-poly.h
Only in gcc/: graphite.c
Only in gcc/: gsstruct.def
Only in gcc/: gstab.h
Only in gcc/: gsyms.h
Only in gcc/: gsyslimits.h
Only in gcc/: gtm-builtins.def
Only in gcc/: haifa-sched.c
Only in gcc/: hard-reg-set.h
Only in gcc/: highlev-plugin-common.h
Only in gcc/: hooks.c
Only in gcc/: hooks.h
Only in gcc/: host-default.c
Only in gcc/: hosthooks-def.h
Only in gcc/: hosthooks.h
Only in gcc/: hw-doloop.c
Only in gcc/: hw-doloop.h
Only in gcc/: hwint.c
Only in gcc/: hwint.h
Only in gcc/: ifcvt.c
Only in gcc/: incpath.c
Only in gcc/: incpath.h
Only in gcc/: init-regs.c
Only in gcc/: input.c
Only in gcc/: input.h
Only in gcc/: insn-addr.h
Only in gcc/: insn-notes.def
Only in gcc/: integrate.c
Only in gcc/: integrate.h
Only in gcc/: internal-fn.c
Only in gcc/: internal-fn.def
Only in gcc/: internal-fn.h
Only in gcc/: intl.c
Only in gcc/: intl.h
Only in gcc/: ipa-cp.c
Only in gcc/: ipa-inline-analysis.c
Only in gcc/: ipa-inline-transform.c
Only in gcc/: ipa-inline.c
Only in gcc/: ipa-inline.h
Only in gcc/: ipa-prop.c
Only in gcc/: ipa-prop.h
Only in gcc/: ipa-pure-const.c
Only in gcc/: ipa-ref-inline.h
Only in gcc/: ipa-ref.c
Only in gcc/: ipa-ref.h
Only in gcc/: ipa-reference.c
Only in gcc/: ipa-reference.h
Only in gcc/: ipa-split.c
Only in gcc/: ipa-utils.c
Only in gcc/: ipa-utils.h
Only in gcc/: ipa.c
Only in gcc/: ira-build.c
Only in gcc/: ira-color.c
Only in gcc/: ira-conflicts.c
Only in gcc/: ira-costs.c
Only in gcc/: ira-emit.c
Only in gcc/: ira-int.h
Only in gcc/: ira-lives.c
Only in gcc/: ira.c
Only in gcc/: ira.h
Only in gcc/: java
Only in gcc/: jump.c
Only in gcc/: langhooks-def.h
Only in gcc/: langhooks.c
Only in gcc/: langhooks.h
Only in gcc/: lcm.c
Only in gcc/: libfuncs.h
Only in gcc/: limitx.h
Only in gcc/: limity.h
Only in gcc/: lists.c
Only in gcc/: loop-doloop.c
Only in gcc/: loop-init.c
Only in gcc/: loop-invariant.c
Only in gcc/: loop-iv.c
Only in gcc/: loop-unroll.c
Only in gcc/: loop-unswitch.c
Only in gcc/: lower-subreg.c
Only in gcc/: lto
Only in gcc/: lto-cgraph.c
Only in gcc/: lto-compress.c
Only in gcc/: lto-compress.h
Only in gcc/: lto-opts.c
Only in gcc/: lto-section-in.c
Only in gcc/: lto-section-out.c
Only in gcc/: lto-streamer-in.c
Only in gcc/: lto-streamer-out.c
Only in gcc/: lto-streamer.c
Only in gcc/: lto-streamer.h
Only in gcc/: lto-symtab.c
Only in gcc/: lto-wrapper.c
Only in gcc/: machmode.def
Only in gcc/: machmode.h
Only in gcc/: main.c
Only in gcc/: matrix-reorg.c
Only in gcc/: mcf.c
Only in gcc/: mips-tdump.c
Only in gcc/: mips-tfile.c
Only in gcc/: mkconfig.sh
Only in gcc/: mode-classes.def
Only in gcc/: mode-switching.c
Only in gcc/: modulo-sched.c
Only in gcc/: objc
Only in gcc/: objcp
Only in gcc/: omega.c
Only in gcc/: omega.h
Only in gcc/: omp-builtins.def
Only in gcc/: omp-low.c
Only in gcc/: opt-functions.awk
Only in gcc/: opt-gather.awk
Only in gcc/: opt-include.awk
Only in gcc/: opt-read.awk
Only in gcc/: optabs.c
Only in gcc/: optabs.h
Only in gcc/: optc-gen.awk
Only in gcc/: optc-save-gen.awk
Only in gcc/: opth-gen.awk
Only in gcc/: opts-common.c
Only in gcc/: opts-diagnostic.h
Only in gcc/: opts-global.c
Only in gcc/: opts.c
Only in gcc/: opts.h
Only in gcc/: output.h
Only in gcc/: params.c
Only in gcc/: params.def
Only in gcc/: params.h
Only in gcc/: passes.c
diff -cpr .pc/symdb_enhance_plugin/gcc/plugin.c gcc/plugin.c
*** .pc/symdb_enhance_plugin/gcc/plugin.c	Wed Jun 20 09:09:15 2012
--- gcc/plugin.c	Wed Jun 20 09:35:20 2012
*************** register_callback (const char *plugin_na
*** 439,444 ****
--- 439,453 ----
        case PLUGIN_EARLY_GIMPLE_PASSES_START:
        case PLUGIN_EARLY_GIMPLE_PASSES_END:
        case PLUGIN_NEW_PASS:
+       case PLUGIN_CPP_TOKEN:
+       case PLUGIN_C_TOKEN:
+       case PLUGIN_EXTERN_DECL:
+       case PLUGIN_EXTERN_FUNC_OLD_PARAM:
+       case PLUGIN_EXTERN_FUNC:
+       case PLUGIN_EXTERN_VAR:
+       case PLUGIN_EXTERN_DECLSPECS:
+       case PLUGIN_CALL_FUNCTION:
+       case PLUGIN_ENUMERATOR:
          {
            struct callback_info *new_callback;
            if (!callback)
*************** invoke_plugin_callbacks_full (int event,
*** 516,521 ****
--- 525,539 ----
        case PLUGIN_EARLY_GIMPLE_PASSES_START:
        case PLUGIN_EARLY_GIMPLE_PASSES_END:
        case PLUGIN_NEW_PASS:
+       case PLUGIN_CPP_TOKEN:
+       case PLUGIN_C_TOKEN:
+       case PLUGIN_EXTERN_DECL:
+       case PLUGIN_EXTERN_FUNC_OLD_PARAM:
+       case PLUGIN_EXTERN_FUNC:
+       case PLUGIN_EXTERN_VAR:
+       case PLUGIN_EXTERN_DECLSPECS:
+       case PLUGIN_CALL_FUNCTION:
+       case PLUGIN_ENUMERATOR:
          {
            /* Iterate over every callback registered with this event and
               call it.  */
diff -cpr .pc/symdb_enhance_plugin/gcc/plugin.def gcc/plugin.def
*** .pc/symdb_enhance_plugin/gcc/plugin.def	Wed Jun 20 09:09:15 2012
--- gcc/plugin.def	Wed Jun 20 09:35:20 2012
*************** DEFEVENT (PLUGIN_EARLY_GIMPLE_PASSES_END
*** 92,97 ****
--- 92,125 ----
  /* Called when a pass is first instantiated.  */
  DEFEVENT (PLUGIN_NEW_PASS)
  
+ /* Called when a cpp token is extracted.  */
+ DEFEVENT (PLUGIN_CPP_TOKEN)
+ 
+ /* Called when a c token is extracted.  */
+ DEFEVENT (PLUGIN_C_TOKEN)
+ 
+ /* An extern declaration (file-scope) is encounted. */
+ DEFEVENT (PLUGIN_EXTERN_DECL)
+ 
+ /* Cooperate PLUGIN_EXTERN_FUNC to parse a function with old-style parameter
+  * declaration. */
+ DEFEVENT (PLUGIN_EXTERN_FUNC_OLD_PARAM)
+ 
+ /* Called when an extern function definition is parsed. */
+ DEFEVENT (PLUGIN_EXTERN_FUNC)
+ 
+ /* Called when an extern variable definition is parsed. */
+ DEFEVENT (PLUGIN_EXTERN_VAR)
+ 
+ /* An extern declaration specifier definition is parsed. */
+ DEFEVENT (PLUGIN_EXTERN_DECLSPECS)
+ 
+ /* A function is called. */
+ DEFEVENT (PLUGIN_CALL_FUNCTION)
+ 
+ /* Called when an enumerator is parsed. */
+ DEFEVENT (PLUGIN_ENUMERATOR)
+ 
  /* After the hard-coded events above, plugins can dynamically allocate events
     at run time.
     PLUGIN_EVENT_FIRST_DYNAMIC only appears as last enum element.  */
Only in gcc/: plugin.h
Only in gcc/: po
Only in gcc/: pointer-set.c
Only in gcc/: pointer-set.h
Only in gcc/: postreload-gcse.c
Only in gcc/: postreload.c
Only in gcc/: predict.c
Only in gcc/: predict.def
Only in gcc/: predict.h
Only in gcc/: prefix.c
Only in gcc/: prefix.h
Only in gcc/: pretty-print.c
Only in gcc/: pretty-print.h
Only in gcc/: print-rtl.c
Only in gcc/: print-tree.c
Only in gcc/: profile.c
Only in gcc/: profile.h
Only in gcc/: read-md.c
Only in gcc/: read-md.h
Only in gcc/: read-rtl.c
Only in gcc/: real.c
Only in gcc/: real.h
Only in gcc/: realmpfr.c
Only in gcc/: realmpfr.h
Only in gcc/: recog.c
Only in gcc/: recog.h
Only in gcc/: ree.c
Only in gcc/: reg-notes.def
Only in gcc/: reg-stack.c
Only in gcc/: regcprop.c
Only in gcc/: reginfo.c
Only in gcc/: regmove.c
Only in gcc/: regrename.c
Only in gcc/: regrename.h
Only in gcc/: regs.h
Only in gcc/: regset.h
Only in gcc/: regstat.c
Only in gcc/: reload.c
Only in gcc/: reload.h
Only in gcc/: reload1.c
Only in gcc/: reorg.c
Only in gcc/: resource.c
Only in gcc/: resource.h
Only in gcc/: rtl-error.c
Only in gcc/: rtl-error.h
Only in gcc/: rtl.c
Only in gcc/: rtl.def
Only in gcc/: rtl.h
Only in gcc/: rtlanal.c
Only in gcc/: rtlhooks-def.h
Only in gcc/: rtlhooks.c
Only in gcc/: sbitmap.c
Only in gcc/: sbitmap.h
Only in gcc/: sched-deps.c
Only in gcc/: sched-ebb.c
Only in gcc/: sched-int.h
Only in gcc/: sched-rgn.c
Only in gcc/: sched-vis.c
Only in gcc/: sdbout.c
Only in gcc/: sdbout.h
Only in gcc/: sel-sched-dump.c
Only in gcc/: sel-sched-dump.h
Only in gcc/: sel-sched-ir.c
Only in gcc/: sel-sched-ir.h
Only in gcc/: sel-sched.c
Only in gcc/: sel-sched.h
Only in gcc/: sese.c
Only in gcc/: sese.h
Only in gcc/: simplify-rtx.c
Only in gcc/: sparseset.c
Only in gcc/: sparseset.h
Only in gcc/: sreal.c
Only in gcc/: sreal.h
Only in gcc/: ssaexpand.h
Only in gcc/: stab.def
Only in gcc/: stack-ptr-mod.c
Only in gcc/: statistics.c
Only in gcc/: statistics.h
Only in gcc/: stmt.c
Only in gcc/: stor-layout.c
Only in gcc/: store-motion.c
Only in gcc/: streamer-hooks.c
Only in gcc/: streamer-hooks.h
Only in gcc/: stringpool.c
Only in gcc/: sync-builtins.def
Only in gcc/: system.h
Only in gcc/: target-def.h
Only in gcc/: target-globals.c
Only in gcc/: target-globals.h
Only in gcc/: target-hooks-macros.h
Only in gcc/: target.def
Only in gcc/: target.h
Only in gcc/: targhooks.c
Only in gcc/: targhooks.h
Only in gcc/: testsuite
Only in gcc/: timevar.c
Only in gcc/: timevar.def
Only in gcc/: timevar.h
Only in gcc/: tlink.c
Only in gcc/: toplev.c
Only in gcc/: toplev.h
Only in gcc/: tracer.c
Only in gcc/: trans-mem.c
Only in gcc/: trans-mem.h
Only in gcc/: tree-affine.c
Only in gcc/: tree-affine.h
Only in gcc/: tree-browser.c
Only in gcc/: tree-browser.def
Only in gcc/: tree-call-cdce.c
Only in gcc/: tree-cfg.c
Only in gcc/: tree-cfgcleanup.c
Only in gcc/: tree-chrec.c
Only in gcc/: tree-chrec.h
Only in gcc/: tree-complex.c
Only in gcc/: tree-data-ref.c
Only in gcc/: tree-data-ref.h
Only in gcc/: tree-dfa.c
Only in gcc/: tree-diagnostic.c
Only in gcc/: tree-diagnostic.h
Only in gcc/: tree-dump.c
Only in gcc/: tree-dump.h
Only in gcc/: tree-eh.c
Only in gcc/: tree-emutls.c
Only in gcc/: tree-flow-inline.h
Only in gcc/: tree-flow.h
Only in gcc/: tree-if-conv.c
Only in gcc/: tree-inline.c
Only in gcc/: tree-inline.h
Only in gcc/: tree-into-ssa.c
Only in gcc/: tree-iterator.c
Only in gcc/: tree-iterator.h
Only in gcc/: tree-loop-distribution.c
Only in gcc/: tree-mudflap.c
Only in gcc/: tree-mudflap.h
Only in gcc/: tree-nested.c
Only in gcc/: tree-nomudflap.c
Only in gcc/: tree-nrv.c
Only in gcc/: tree-object-size.c
Only in gcc/: tree-optimize.c
Only in gcc/: tree-outof-ssa.c
Only in gcc/: tree-parloops.c
Only in gcc/: tree-pass.h
Only in gcc/: tree-phinodes.c
Only in gcc/: tree-predcom.c
Only in gcc/: tree-pretty-print.c
Only in gcc/: tree-pretty-print.h
Only in gcc/: tree-profile.c
Only in gcc/: tree-scalar-evolution.c
Only in gcc/: tree-scalar-evolution.h
Only in gcc/: tree-sra.c
Only in gcc/: tree-ssa-address.c
Only in gcc/: tree-ssa-alias.c
Only in gcc/: tree-ssa-alias.h
Only in gcc/: tree-ssa-ccp.c
Only in gcc/: tree-ssa-coalesce.c
Only in gcc/: tree-ssa-copy.c
Only in gcc/: tree-ssa-copyrename.c
Only in gcc/: tree-ssa-dce.c
Only in gcc/: tree-ssa-dom.c
Only in gcc/: tree-ssa-dse.c
Only in gcc/: tree-ssa-forwprop.c
Only in gcc/: tree-ssa-ifcombine.c
Only in gcc/: tree-ssa-live.c
Only in gcc/: tree-ssa-live.h
Only in gcc/: tree-ssa-loop-ch.c
Only in gcc/: tree-ssa-loop-im.c
Only in gcc/: tree-ssa-loop-ivcanon.c
Only in gcc/: tree-ssa-loop-ivopts.c
Only in gcc/: tree-ssa-loop-manip.c
Only in gcc/: tree-ssa-loop-niter.c
Only in gcc/: tree-ssa-loop-prefetch.c
Only in gcc/: tree-ssa-loop-unswitch.c
Only in gcc/: tree-ssa-loop.c
Only in gcc/: tree-ssa-math-opts.c
Only in gcc/: tree-ssa-operands.c
Only in gcc/: tree-ssa-operands.h
Only in gcc/: tree-ssa-phiopt.c
Only in gcc/: tree-ssa-phiprop.c
Only in gcc/: tree-ssa-pre.c
Only in gcc/: tree-ssa-propagate.c
Only in gcc/: tree-ssa-propagate.h
Only in gcc/: tree-ssa-reassoc.c
Only in gcc/: tree-ssa-sccvn.c
Only in gcc/: tree-ssa-sccvn.h
Only in gcc/: tree-ssa-sink.c
Only in gcc/: tree-ssa-strlen.c
Only in gcc/: tree-ssa-structalias.c
Only in gcc/: tree-ssa-tail-merge.c
Only in gcc/: tree-ssa-ter.c
Only in gcc/: tree-ssa-threadedge.c
Only in gcc/: tree-ssa-threadupdate.c
Only in gcc/: tree-ssa-uncprop.c
Only in gcc/: tree-ssa-uninit.c
Only in gcc/: tree-ssa.c
Only in gcc/: tree-ssanames.c
Only in gcc/: tree-stdarg.c
Only in gcc/: tree-stdarg.h
Only in gcc/: tree-streamer-in.c
Only in gcc/: tree-streamer-out.c
Only in gcc/: tree-streamer.c
Only in gcc/: tree-streamer.h
Only in gcc/: tree-switch-conversion.c
Only in gcc/: tree-tailcall.c
Only in gcc/: tree-vect-data-refs.c
Only in gcc/: tree-vect-generic.c
Only in gcc/: tree-vect-loop-manip.c
Only in gcc/: tree-vect-loop.c
Only in gcc/: tree-vect-patterns.c
Only in gcc/: tree-vect-slp.c
Only in gcc/: tree-vect-stmts.c
Only in gcc/: tree-vectorizer.c
Only in gcc/: tree-vectorizer.h
Only in gcc/: tree-vrp.c
Only in gcc/: tree.c
Only in gcc/: tree.def
Only in gcc/: tree.h
Only in gcc/: treestruct.def
Only in gcc/: tsystem.h
Only in gcc/: typeclass.h
Only in gcc/: value-prof.c
Only in gcc/: value-prof.h
Only in gcc/: var-tracking.c
Only in gcc/: varasm.c
Only in gcc/: varpool.c
Only in gcc/: vec.c
Only in gcc/: vec.h
Only in gcc/: vecir.h
Only in gcc/: vecprim.h
Only in gcc/: version.c
Only in gcc/: version.h
Only in gcc/: vmsdbg.h
Only in gcc/: vmsdbgout.c
Only in gcc/: web.c
Only in gcc/: xcoff.h
Only in gcc/: xcoffout.c
Only in gcc/: xcoffout.h

[-- Attachment #5: 471.tgz --]
[-- Type: application/x-gzip, Size: 62877 bytes --]

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

* Re: [PATCH 1/2] gcc symbol database
  2012-06-21  7:48     ` Yunfeng ZHANG
@ 2012-06-27  8:46       ` Yunfeng ZHANG
  2012-07-13 19:32       ` Dodji Seketeli
  1 sibling, 0 replies; 18+ messages in thread
From: Yunfeng ZHANG @ 2012-06-27  8:46 UTC (permalink / raw)
  To: Dodji Seketeli; +Cc: gcc-patches, Joseph S. Myers, Dave Korn, Tom Tromey

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

Hi Dodji Seketeli:

Is it possible to gcc to accept libcpp.patch and plugin.patch?

I recently rewrite my doc.txt which mainly add a new section <Macro
Expansion Overview>, it's focused on pfile.context usage linking to
macro. I think it's important to use cb_macro_start/end callbacks
because most users only care about the outest macro expansion, test
whether pfile.context.prev == NULL, however if he hasn't known macro
cascaded case, his code will crashed.

Sincerely
                                                                     Yunfeng

[-- Attachment #2: doc.txt --]
[-- Type: text/plain, Size: 17118 bytes --]

// vim: foldmarker=<([{,}])> foldmethod=marker
                         Gcc symbol database (symdb)
                             zyf.zeroos@gmail.com
                              November 24, 2009
                           revised on May 24, 2012

// Purpose <([{
The file is used to record the idea I got -- collecting gcc internal data
(definition, file-dependence etc.) and outputting them into database for
further usage.  Have you knowed cscope? but I think it's more appropriate that
symbols should be collected by gcc itself. Later sections can be cataloged
into two genres

For user (here user is IDE-like develop tools, not final user)
1) Need to know what symdb can do, goto section <Feature List>.
2) Goto section <User Manual> for how to using symdb.
3) <Multiple results> and <Tested cases> have more about the plugin.
For gcc internal developer
1) Section <New Token Type> defines some new token types used in my symdb.
2) Sections <Gcc XXXX Macro Expansion> shows some complex cases linking to
macro expansion, I list calling sequence from plugin-side and stack snapshot
from gcc-side in every section, read them carefully, it's the key to
understand so.c:class mo.  test/testplan.txt and test/macro have the
testcases.
3) Section <Patch Overview> makes focus on which files and how are changed in
the patch.

Before we go, let's clear up some terminology or abbreviation used in my symdb
1) cpp abbreviates from c preprocess (follows gcc intern convention); however,
cxx represents c++.
2) In gcc/c-ppoutput.c, gcc defines compilation unit as compiling a file, new
noun `compilation session' means compiling all files of a project.
// }])>

For User
// Feature List <([{
1) The plugin only works on C not C++.
2) Plugin can collect all extern definitins and dump them to database.
3) As the convention, the members of an extern enum are collected and dumped
to database.
4) Funtion call relationship are collected too, just like cscope.
5) You can use table FileDependence of database to reconstruct file dependence
relationship.
6) Not in cscope, you can use `gs addsym/rmsym' to re-edit the database,
remove the duplicate results and append new symbols to the database, see
section <Multiple-results ...>.
7) I finished a vim script `helper.vim' to help you using the database in vim.
8) My plugin is better than cscope in any cases, since I can catch definition
after macro expansion (such as tell you where `sys_open' is defined in linux
source) and skip `#ifdef/#if'.
// }])>

// User Manual <([{
Note: Using my plugin on correct code, buggy code maybe cause my plugin
infinite-loop.

Prepare stage (patch on gcc-4.6.3):
1) cp gcc.patches/* gcc.src/patches
2) quilt push -a
3) make # as usual
More about compilation suite (such as crosstool-ng-1.13.2):
1) Since gcc plugin is implemented as shared library, so disable compiling
static toolchain option.
2) add `--enable-plugin' to your gcc configure line, or append
`CT_CC_GCC_ENABLE_PLUGINS=y' to your crossng.config.
3) See section <Tested cases> for a sample command line on gcc-4.6.3.

Compiling source by patched gcc (cd myplugin.src/):
1) make
2) cp gs helper.vim init.sql target.src/ && cd target.src/
3) ./gs initdb ./ # Initialize database. If you want to custom the plugin,
update plugin-control-fields of database:ProjectOverview.
4) Append `-fplugin=/path/to/symdb.so
-fplugin-arg-symdb-dbfile=/target.src/gccsym.db' to your CFLAGS.
5) Since sqlite uses file-lock to synchronize database, so use `make -j1' to
compile source.
6) It will cost more time to compile your project, because my plugin need
compare whether a token has been inserted into database and multi-core can't
help you -- see previous steps, do it overnight.
7) ./gs vacuumdb ./ # Rearrange and defrag your database.
Of course, you can use some short-cuts to compile your projects without any
modification.
    alias gcc='gccplugin -fplugin=symdb.so -fplugin-arg-symdb-dbfile=gccsym.db'
    alias make='make -j1'

Working with new database:
1) cd /target.src
2) vi
3) execute `:source helper.vim'
4) Using `CTRL-]' to search a definition.
5) Using `CTRL-[' to search which functions calls the function.
6) Using `CTRL-T' to jump back.
7) Using `Gs def yoursymbol' to search a definition.
8) Using `Gs callee yourfunction' to search function call relationship.

Vim quickref:
Since my database stores the file-offset of every token, so
1) Using `:go fileoffset' to jump to the token.
2) Using `g<CTRL-g>' on the char to get the file-offset.

Testing my plugin:
1) cd test && ./run.sh
// }])>

// Multiple-results from my database and my solution <([{
Things are not always perfect, here I list some cases which makes my plugin
return multiple-resuls when search a definition.

    int i;
    int i;
    extern int i;
The syntax is acceped by gcc, so to my plugin, by the way, my plugin doesn't
store the third line to database.

    typedef abc abc;
    struct abc {
        ...
    };
The syntax is correct. `gs' will return two results, one is DEF_TYPEDEF,
another is DEF_STRUCT. In gcc-4.6.2, search `cpp_reader' will see the case, by
the way, `helper.vim' will search definition from current file and its
dependence, then all files, so in libcpp/internal.h searching `cpp_reader'
will return one result.

    #define X a
    #include "afile"
    #undef X
    #define X b
    #include "afile"
    #undef X
Search `X' will return multiple results, gcc/tree.c includes several
gcc/tree.def and definite symbol `DEFTREECODE' several times.

    #ifdef X
    int x;
    #else
    char x;
    #endif
Sometime `x' is returned two results.
glibc-2.13/include/shlib-compat.h:compat_symbol is the case. The reason is
every file is compiled two times in glibc internal
    gcc .. -DSHARED .. -o x.os
    gcc .. -o x.o
It causes the strange case.

Fortunately, I add two commands (not in cscope :)
    gs addsym/rmsym filename definition position
So you can remove the item you doesn't like by them. `gs addsym' is also
useful since you can use it to append the symbols which are invisible from my
plugin, such as `gs addsym arch/mips/kernel/vmlinux.lds jiffies 6601'.
// }])>

// Tested projects (gcc, glibc and linux) <([{
Prepare gcc support packages:
sqlite-autoconf-3070900:
    ./configure --prefix=/home/zyf/root
    make install
gmp-5.0.1
    ./configure --prefix=/home/zyf/root/ --enable-shared=no && make install
mpfr-3.0.1
    ./configure --prefix=/home/zyf/root/ --with-gmp=/home/zyf/root/
    --enable-shared=no && make install
mpc-0.9
    ./configure --prefix=/home/zyf/root/ --with-mpfr=/home/zyf/root/
    --with-gmp=/home/zyf/root/ --enable-shared=no && make install
gcc-4.6.3 (x86):
    *) ./configure --prefix=/home/zyf/root/ --with-mpc=/home/zyf/root/
    --with-gmp=/home/zyf/root/ --with-mpfr=/home/zyf/root/
    *) # After quilt my patches.
    *) make STAGE1_CFLAGS="-ggdb" all-stage1
    *) # prepare database.
    *) make STAGE2_CFLAGS="-fplugin=/home/zyf/src/symdb.gcc/symdb.so
    -fplugin-arg-symdb-dbfile=/home/zyf/src/gcc-4.6.3/gccsym.db" all-stage2
    *) # rearrange database.
glibc-2.13 (mips):
    *) Change glibc.src/Makeconfig: `override CFLAGS = '.
linux-2.6.35 (mips):
    *) Change linux.src/Makefile: `KBUILD_CFLAGS := '.
// }])>

For Developer
// New Token Type <([{
In this section, I'll define some new token type which is available everywhere
in my symdb, but before we go, we need go further into gcc internal on how gcc
compiles a file, consider the case

    ----------- a.c -----------
    #define FOO \
        = 2;
    // a line comment only.
    ...
    int x FOO;

Now do `gcc -save-temps --verbose a.c', you will get all intermediate files
and gcc call hierarchy -- main, preprocess, compiling, assemble and linkage
stage. Comparing a.c and a.i, we find some tokens are erased, some are
substituted, so my new token types are
1) EXPANDED_TOKEN -- is macro-expanded or substituted (`FOO' of the last
line).
2) ERASED_TOKEN -- erased during preprocess stage (The first 3 lines).
3) COMMON_TOKEN -- exist in both .c and .i.
4) MACRO_TOKEN -- macro result (sample is `=' and `2').

And
*) Original .c/.h include the first 3 types -- also called chToken.
*) .i includes the last 2 types -- called iToken.
*) To function-like macro, such as, `x', `(', `a', `)', all four tokens are
EXPANDED_TOKEN, and the first is also called leader EXPANDED_TOKEN.

By the way, preprocess stage also combines all soft carriage line -- tailing
with `\' into a line, so the first 2 lines are combined, and `\' itself isn't
cpp token.
// }])>

// Macro Expansion Overview, based on gcc-4.6.3 <([{
The fold records gcc macro expansion internal flow and my implementation,
generally when macro expansion occurs, new context is pushed into
pfile.context and its context.macro != NULL, however later lines show there're
other cases using pfile.context too and context.macro = NULL. Note we ignore
pragma, conditional macro, error handling, traditional macro lines.
Terminology:
    1) paste case: `#define A x ## y'. To `x' token.flags & PASTE_LEFT.
    2) stringify case: `#define A(x) #x'. To `x' token.flags & STRINGIFY_ARG.

cpp_get_token:
    _cpp_lex_token
    if token.flags == PASTE_LEFT, paste_all_tokens. context.macro = NULL.
    _cpp_pop_context, cb_macro_end is broadcasted.
    cb_macro_start is broadcasted, enter_macro_context

enter_macro_context:
    If fun_like:
        funlike_invocation_p (>> collect_args), and when macro cascaded, it
            pushes a context.macro = NULL.
        replace_args, see below.
    If !fun_like:
        _cpp_push_token_context, context.macro != NULL.

// replace_args: tags paste tokens and handles stringify cases <([{
Iterate macro tokens and handle CPP_MACRO_ARG.
    stringify case: call stringify_arg.
    paste case: do nothing.
    macro case: call expand_arg which context.macro = NULL.
Do replacement:
    token literally copy from user token and continue.
    otherwise CPP_MACRO_ARG, do later
    1) insert padding token before the arg unless it's the first token.
    `!(src[-1].flags & PASTE_LEFT)'.
    2) copy arg result.
    3) insert padding token after args. The token is pfile.avoid_paste
    (CPP_PADDING). `if !(src->flags & PASTE_LEFT)'.
Call push_ptoken_context, context.macro != NULL.

So to case 1:
    #define xglue(x, y) x y
    `x', CPP_PADDING (post-padding), CPP_PADDING (pre-padding), `y',
    CPP_PADDING (post-padding).
So to case 2:
    #define xglue(x, y) x ## y
    `x', `y', CPP_PADDING (post-padding).
    And `x' token.flags = PASTE_LEFT.
// }])>

// Context conclusion <([{
cpp_get_token calls _cpp_pop_context.
paste_all_tokens calls _cpp_push_token_context, context.macro = NULL.
enter_macro_context calls _cpp_push_token_context if !funlike.
funlike_invocation_p calls _cpp_push_token_context if macro cascaded.
replace_args calls push_ptoken_context to contain macro result.
expand_arg calls push_ptoken_context/_cpp_pop_context, context.macro = NULL.
// }])>

Keep it in mind when cb_macro_start is called, new macro context has NOT
pushed, to cb_macro_end context has been poped. To my plugin, only the outest
macro expansion is cared about, which means, to the callbacks, we should
detect whether pfile.context.prev == NULL, however section <GCC cascaded macro
expansion> shows there's a trap in it. Read replace_args carefully, it will
help to understand mo_maybe_cascaded.
// }])>

// GCC Cancel Macro Expansion <([{
Consider the case
    #define Z(a) a
    int Z = 3;

in fact, gcc doesn't complain the last line. After prefetch two tokens `Z' and
`=', gcc realizes that `Z' shouldn't be treated as macro, so it cancels macro
expansion and return `Z' and `=' as COMMON_TOKEN not EXPANDED_TOKEN. However
it makes my code flow become more complex, I place a bool mo.cancel to solve
it.

Calling sequence (Note, cb_macro_start and cb_macro_end are always matched
even macro expansion is canceled):
    cb_macro_start(Z)
    cb_end_arg(cancel = true)
    cb_macro_end(Z, prev = NULL)
    symdb_cpp_token('Z')
    symdb_cpp_token('=')

By the way, my plugin only cares about 1-level macro cancel.
// }])>

// GCC Cascaded Macro Expansion <([{
Consider the case
    #define Z(a) a
    #define Y Z
    #define X Z(1)
    Y(1);
    X;

The case is special due to the expansion process of X and Y is converted to
the expansion process of a fun-like macro finally.

To the fourth line, the sequence is
    cb_macro_start(Y)
    cb_macro_start(Z)
# enter_macro_context(Z) >> funlike_invocation_p >> cpp_get_token, Y macro is
# popped from pfile.context, so
    cb_macro_end(Y, prev = NULL)
    cb_end_arg(Z)
# enter_macro_context(Z) >> replace_args. Z macro is pushed to pfile.context.
    symdb_cpp_token(a)
    cb_macro_end(Z, prev = NULL)

To the fifth line, the sequence is
    cb_macro_start(X)
    cb_macro_start(Z)
    cb_end_arg(Z)
    cb_macro_end(Z)
    cb_macro_end(X, prev = NULL)

The fourth line is also breaking cb_macro_start/cb_macro_end pair rule. It
makes my code a little complex. I use mo_maybe_cascaded() to solve it.

Note: macro cascaded means the tail of a macro expansion tokens is another
funlike macro. So later macro definition is also belongs to macro cascade.
    #define Y2 1 + Z
But later isn't
    #define Y2 1 + Z + 1

To 3-level or higher cascaded cases, it's obvious all immediate macroes can't
be funlike macro. Here only list the first sequence
    cb_macro_start(Y)
    cb_macro_start(Y2)
    cb_macro_start(Y3)
    cb_macro_start(Z)
    ...
// }])>

// GCC Cancel + Cascaded Macro Expansion <([{
Consider the case
    #define Z(p) a
    #define Y Z
    #define X Z = 1
    int Y = 1;
    int X;

When cancel encounters cascaded, thing will go even worse.

To the fourth line, the sequence is
    cb_macro_start(Y)
    cb_macro_start(Z)
# enter_macro_context(Z) >> funlike_invocation_p >> cpp_get_token, Y macro is
# popped from pfile.context, so
    cb_macro_end(Y, prev = NULL)
# Then Z is canceled, funlike_invocation_p >> _cpp_push_token_context which
# pushes a context to pfile.context, its context.macro = NULL.
    cb_end_arg(cancel = true)
# So in my cb_macro_end, prev != NULL, however its context.macro = NULL, a
# strange case.
    cb_macro_end(Z, match-pair to cb_end_arg, prev != NULL)
    symdb_cpp_token(`Z' is returned, which is the result of Y macro)
    cb_macro_end(prev = NULL)
# context.macro = NULL is poped.
    symdb_cpp_token(=)

To the fifth line, the sequence is
    cb_macro_start(X)
    cb_macro_start(Z)
    cb_end_arg(cancel = true)
    cb_macro_end(Z, match-pair to cb_end_arg)
    symdb_cpp_token(Z)
    symdb_cpp_token(=)
    symdb_cpp_token(1)
    cb_macro_end(X, prev = NULL)

To the fourth line, two cb_macro_start and three cb_macro_end are called.
// }])>

// Patch Overview <([{
// symdb_enhance_libcpp <([{
Several new callbacks are appended into libpp/include/cpplib.h:cpp_callbacks:
void (*macro_start_expand) (...);
void (*macro_end_arg) (..., bool cancel);
void (*macro_end_expand) (...);
    are used to collect EXPANDED_TOKEN and MACRO_TOKEN.
Note:
1) macro_end_arg is callbacked when a function-like macro ends to collect
its arguments.
2) See section <GCC Cancel Macro Expansion> for more about parameter cancel of
macro_end_arg.
3) macro_{start, end}_expand can be called several times if the macro includes
more macroes in its define clause.
4) Even macro expansion cancel, a macro_end_expand is called too.
void (*start_directive) (...);
void (*end_directive) (...);
void (*directive_token) (...);
    are used to collect ERASED_TOKEN. Meanwhile, directive_token is much
powerful than cpp_get_token since cpp_get_token doesn't output ERASED_TOKEN.
Most code in libcpp directory is surrounding how to implement the callbacks.

A new field -- file_offset is added into cpplib.h:cpp_token, the field is used
to mark every chToken exclusively, it's just like line_map + source_location,
but simpler, and to show line/column to user new script offset2lc(filename,
fileoffset, &line, &column) should be used. internal.h:_cpp_line_note is also
changed to fit with the purpose.
// }])>

// symdb_enhance_plugin <([{
New events are added into current plugin architecture
PLUGIN_CPP_TOKEN
PLUGIN_C_TOKEN
PLUGIN_EXTERN_DECL
PLUGIN_EXTERN_FUNC_OLD_PARAM
PLUGIN_EXTERN_FUNC
PLUGIN_EXTERN_VAR
PLUGIN_EXTERN_DECLSPECS
PLUGIN_CALL_FUNCTION
PLUGIN_ENUM_SPECIFIER
The first two events are used to cache iToken, the remain are used to collect
definition.
// }])>
// }])>

// Database (init.sql) <([{
*) User should use the fields of ProjectOverview to control the plugin.
*) User should use view Helper to search file, definition and position.
*) Using `gs initdb/vacuumdb' to initialize database and arrange it.

init.sql has been organized by vim fold feature. Meanwhile table chFile is
the root.
// }])>

// Misc. <([{
Gcc defines a default cpp_callbacks::file_change, to listen the callback in my
patch to monitor file depedence, I replace the value in symdb_unit_init and
call the original value in cb_file_change.

New field cpp_token::file_offset breaks the fact the size of cpp_token should
be fit with a cacheline. See section <Patch Overview> for the solution.
// }])>

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

* Re: [PATCH 1/2] gcc symbol database
  2012-06-21  7:48     ` Yunfeng ZHANG
  2012-06-27  8:46       ` Yunfeng ZHANG
@ 2012-07-13 19:32       ` Dodji Seketeli
  2012-07-16 10:09         ` Yunfeng ZHANG
  1 sibling, 1 reply; 18+ messages in thread
From: Dodji Seketeli @ 2012-07-13 19:32 UTC (permalink / raw)
  To: Yunfeng ZHANG; +Cc: gcc-patches, Joseph S. Myers, Dave Korn, Tom Tromey

> I'm sorry recent weeks I've got busy

No problem.  I am sorry to reply this late to your message as well.

> Later is the response from previous mail.

Please do not take this bad, but it will really ease communication (and
the review) if, when you reply to this message, you write your answers
*below* the parts of you are replying to, and remove the parts (of my
message) you are not replying to.  I believe this is a good habit to
have at least when you are interacting with the GCC mailing lists.

Now here are my comments on your patches.

> -------------------------
> macro_end_expand can't be moved to _cpp_pop_context. My plugin shows later
> results when `Gs callee _cpp_pop_context'.
> 	GS multiple definition:
> 	1)libcpp/directives.c 8130 skip_rest_of_line DEF_FUNC
> 	2)libcpp/macro.c 67161 expand_arg DEF_FUNC
> 	3)libcpp/macro.c 72900 cpp_get_token_1 DEF_FUNC
> 	4)libcpp/traditional.c 10560 _cpp_scan_out_logical_line DEF_FUNC

I still think that the macro_end_expand can and should be moved to
_cpp_pop_context, even though that function is called from multiple
places.  That is, in the 'if' block:

  if (context->c.macro)
    {

you just have to write something like:

    if (in_macro_expansion_p)
      /* We are at the end of the expansion of a macro.  */
      macro_end_expand (...);

This is what I was trying to tell you in my previous message, when I was
saying:

    > _cpp_pop_context is really the function that marks the end of a
    > given macro expansion, especially when the predicate
    > in_macro_expansion_p (introduced recently in trunk for gcc 4.8)
    > returns true.

Am I missing something?

> So macro_start_expand can't be moved to enter_macro_context since the pair
> should be matched in the same function cpp_get_token_1.

In the light of what I said above, I think macro_start_expand should
be moved to enter_macro_context, if you agree with my previous
statements.


> 1) macro_start_expand and macro_end_arg are used to tag all macro
  tokens.

I think there are some concepts that need to be a bit more clearly
stated here, otherwise we'll be talking past each other.

You are basically making the pre-processor emit events at some useful
points of its operations.  And then, your client code (the code of
your plugin) reacts whenever these useful events are emitted.  It
reacts to these events to accomplish some useful tasks.

The tasks your wants to accomplish here, somehow, is to mark the tokens
that results from the expansion of a macro.

Right?

I think it will make the code more maintainable to have the events be
emitted at points that are "well defined".  And this is where I am
having issues with your patch.

So, it seems clear to me that macro_start_expand is an event that is
emitted at the beginning of the expansion of a macro.

But the "meaning" of the macro_end_arg event is really not clear to
me.  From your code, it looks like it's a hack that lets you detect if
the macro_start_expand event really was emitted in cases where we are
sure that the macro is going to be expanded.

Let me explain a bit more.

When a macro M is encountered, enter_macro_context triggers its
expansion; but sometimes it does not.  And what I understand is that, in
an ideal world, you want to call macro_start_expand only in cases where
enter_macro_context actually triggers the expansion.  That way, your
plugin can use the tokens of the replacement-list of M (passed to
macro_start_expand) as it sees fit.

But in this patch, you are going a hackish route by unconditionally
calling macro_start_expand whenever M is encountered (right after
enter_macro_context is called), and if enter_macro_context does *not*
trigger the expansion of M, you tell your plugin to "back out", by
calling macro_end_arg with its 'cancel' parameter set to a 'true'
boolean.  Otherwise, if enter_macro_context happens to really have
expanded M, you are calling macro_end_arg with its 'cancel' parameter
set to a 'false' value, effectively telling your plugin "OK, M was
really expanded".

And what I was saying in my previous email is that you could arrange
to emit the macro_start_expand event *only* when you are sure that
enter_macro_context is really going to expand M.

That is why I was saying in my previous message:

    > IMHO, it's more maintainable to put the call to
    > pfile->cb.macro_start_expand inside enter_macro_context, as that
    > is the function that really triggers the macro expansion.

And then, I told you where to put that call in enter_macro_context so
that you are sure to emit the event only when you are sure
enter_macro_context is going to expand M (and I am repeating it here
again):

    > Maybe if you put the call to macro_start_expand in this
    > enter_macro_context function only after we are sure we are going
    > to actually proceed with the expansion ....
    >
    >>            return 0;
    >>          }
    >
    > ... here, then you wouldn't need the macro_end_arg at
    > all.  Would that make sense?


> 2) macro_end_arg and macro_end_expand are used to tag all macro-replacement
> tokens.

To be more precise I'd say that macro_end_expand is an event which
meaning is "This is the end of the expansion of the macro that was
signaled by a previous invocation of macro_start_expand".  And your
plugin reacts to that event by tagging the tokens of the
replacement-list of the macro.

> So macro_start_expand can't be moved to enter_macro_context when I'm
> sure a macro expansion has occured.

I am not sure to understand what you mean here.  If you call
macro_start_expand at the *beginning* of enter_macro_context as I
explained above, then the macro expansion has not *yet* occurred.  But
you are sure that it *will* occur.

> To make potential user free resource, macro_end_expand is called
> even macro is canceled. That's why macro_end_expand is called twice
> in cpp_get_token_1.

If you call macro_start_expand only when you are sure that the macro
is going to be expanded, I believe you don't need to call
macro_end_expand twice.

> If gcc can't accept cpp_token::file_offset field, I can change my plugin
> stores token linenum other than token file_offset to database, final user
> should be tolerate with it.

You still don't reply to the key questions that I have asked you in my
previous email:


    > So why is this file_offset member needed?
    >
    > From the rest of the patch, it looks like you are using it to
    > store the offset of the token, from the beginning of its
    > line.  What is the difference between that, and the column
    > number of the token, as you could get by calling
    > linemap_expand_location on the src_loc of the token, effectively
    > doing away with this new file_offset member?  Note that the
    > linemap_expand_location call was introduced in 4.7.

Please reply to these questions so that I understand why you need this
field at all, rather than getting it from the linemap infrastructure
by calling, for instance, linemap_expand_location.

When these questions are sorted, I think we can go further with the rest
of the review.

> By the way, have you tried my plugin in previous mail?

Not yet.  For now, I am reading the patch.  :-)

Thank you for your time and efforts.

-- 
		Dodji

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

* Re: [PATCH 1/2] gcc symbol database
  2012-07-13 19:32       ` Dodji Seketeli
@ 2012-07-16 10:09         ` Yunfeng ZHANG
  2012-07-16 15:31           ` Dodji Seketeli
  0 siblings, 1 reply; 18+ messages in thread
From: Yunfeng ZHANG @ 2012-07-16 10:09 UTC (permalink / raw)
  To: Dodji Seketeli; +Cc: gcc-patches, Joseph S. Myers, Dave Korn, Tom Tromey

> But the "meaning" of the macro_end_arg event is really not clear to
> ...
> .... and so on.

Let's see a sample:
    #define Z(a) a
    #define Y Z
    #define X(p) p + Y
    X(1)(2);
With my solution, user get
    1) `X' -- leader macro token by macro_start_expand.
    2) `(', `1', `)', `(', `2', `)' -- macro tokens, by cb_lex_token.
    3) macro_end_arg.
    4) `1', `+', `2' -- macro replacement tokens, by symdb_cpp_token.
    5) macro_end_expand.
Item 2 is very important since if `X(1)' doesn't return any macro replacement
tokens, then `(2)' is a legal clause.
So please review my former mail again.

And it seems in gcc-4.8, gcc can trace several contiguous macro expansion
contexts can be associated to the same macro, so macro cascaded case has
disappeared.

> Please reply to these questions so that I understand why you need this
> field at all, rather than getting it from the linemap infrastructure
> by calling, for instance, linemap_expand_location.

linemap_expand_location can return the column and row of a token, not file
offset of its, there's no more explanation why using token file-offset, when I
started my project, I think file-offset is better than current
linemap+source_location because it costed less time to encode/decode
source_location field and can act just like previous solution, it's an
improvement to gcc too, with it gcc can store symbol+fileoffset to elf intern
for ld/gdb usage, of course, my database can benefit from  it -- less space and
use it as sort field directly. The only thing is it make challenge on gcc
infrastructure, so I leave it to a seperate patch called gcc_negotiate_patch
and hope to discuss the first two patches only.

And to the field file-offset, when the token is macro-replacement token, I
recommend token.file_offset = -1 * <leader macro token>.file_offset. I think
gdb is happy to this.

Sincerely
Yunfeng

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

* Re: [PATCH 1/2] gcc symbol database
  2012-07-16 10:09         ` Yunfeng ZHANG
@ 2012-07-16 15:31           ` Dodji Seketeli
  2012-07-17  7:14             ` Yunfeng ZHANG
  0 siblings, 1 reply; 18+ messages in thread
From: Dodji Seketeli @ 2012-07-16 15:31 UTC (permalink / raw)
  To: Yunfeng ZHANG; +Cc: gcc-patches, Joseph S. Myers, Dave Korn, Tom Tromey

Yunfeng ZHANG <zyf.zeroos@gmail.com> writes:

>> But the "meaning" of the macro_end_arg event is really not clear to
>> ...
>> .... and so on.
>
> Let's see a sample:
>     #define Z(a) a
>     #define Y Z
>     #define X(p) p + Y
>     X(1)(2);
> With my solution, user get
>     1) `X' -- leader macro token by macro_start_expand.
>     2) `(', `1', `)', `(', `2', `)' -- macro tokens, by cb_lex_token.
>     3) macro_end_arg.
>     4) `1', `+', `2' -- macro replacement tokens, by symdb_cpp_token.
>     5) macro_end_expand.

I see.  So the meaning of macro_end_arg is something like:

    "The tokens that were just reported by the lex_token event were
     arguments to a function-like macro".

Is that correct?  

If yes, then I guess you can keep that macro_end_arg event, but then I'd
remove its "cancel" argument by doing what I said in my previous
messages.  Which is, don't call macro_start_expand if X is not going to
be expanded.  To do that, move macro_start_expand in
enter_macro_context, like I proposed there.

Of course, that would not change the sequence of the events you'd get in
the example above.  But in this example below:

     1	    #define Y 1
     2	
     3	    int
     4	    Y (int a)
     5	    {
     6	      return a + 1;
     7	    }
     8	
     9	    int
    10	    main ()
    11	    {
    12	      return Y(a);
    13	    }

When parsing Y(a), what I am proposing won't emit a
macro_start_expansion at line 12, but with your implementation, it will
emit a macro_start_expansion, followed by a macro_end_arg with the
cancel argument set to true.  Which is unnecessary if the
macro_start_expansion is not called at all there.

Of course, you'd have to change the hunk:

    *************** enter_macro_context (cpp_reader *pfile, 
    *** 1015,1020 ****
    --- 1015,1022 ----
              pfile->state.parsing_args = 1;
              buff = funlike_invocation_p (pfile, node, &pragma_buff,
                                           &num_args);
    + 	  if (pfile->cb.macro_end_arg)
    + 	    pfile->cb.macro_end_arg (pfile, buff == NULL);
              pfile->state.parsing_args = 0;
              pfile->keep_tokens--;
              pfile->state.prevent_expansion--;

so that "pfile->cb.macro_end_arg (pfile)" is not invoked when
funlike_invocation_p returns NULL.

Does that make sense?

If yes, the comment of that event should be adapted to have a more
meaningful meaning.  I believe the comments of the other events should
be adapted to, in the light of the description that I did in my previous
message.

>> Please reply to these questions so that I understand why you need this
>> field at all, rather than getting it from the linemap infrastructure
>> by calling, for instance, linemap_expand_location.
>
> linemap_expand_location can return the column and row of a token, not file
> offset of its, there's no more explanation why using token file-offset, when I
> started my project, I think file-offset is better than current
> linemap+source_location because it costed less time to encode/decode
> source_location field and can act just like previous solution,

What I meant was that if you prefer storing file offsets in the database
of your plugin, rather than line/column, then why not saying that it's
equal to something like (line + column), instead of adding a new field
in libcpp itself.

> it's an improvement to gcc too, with it gcc can store
> symbol+fileoffset to elf intern for ld/gdb usage, of course,

I wouldn't be so sure.  DWARF already has a sophisticated and compact
way to store line/column information, so I don't think the file offset
gives us anything in practice.

> my database can benefit from it -- less space and use it as sort field
> directly.

Sure, but then you can just compute it from the result of
linemap_expand_location, as I said above.

> The only thing is it make challenge on gcc infrastructure, so I leave
> it to a seperate patch called gcc_negotiate_patch and hope to discuss
> the first two patches only.

If you are not convinced, then OK, let's leave that part aside from now.

> And to the field file-offset, when the token is macro-replacement token, I
> recommend token.file_offset = -1 * <leader macro token>.file_offset. I think
> gdb is happy to this.

Right now, for tokens resulting from macro expansion, the location that
is encoded in debug information is already the location of the expansion
point of the macro.  So we already do what you say, in a sense.

Cheers.

-- 
		Dodji

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

* Re: [PATCH 1/2] gcc symbol database
  2012-07-16 15:31           ` Dodji Seketeli
@ 2012-07-17  7:14             ` Yunfeng ZHANG
  2012-07-17  9:06               ` Dodji Seketeli
  0 siblings, 1 reply; 18+ messages in thread
From: Yunfeng ZHANG @ 2012-07-17  7:14 UTC (permalink / raw)
  To: Dodji Seketeli; +Cc: gcc-patches, Joseph S. Myers, Dave Korn, Tom Tromey

Please allow me to resend former sample:
    #define Z(a) a
    #define Y Z
    #define X(p) p + Y
    X(1)(2);
The flow is:
    1) `X' -- leader macro token by macro_start_expand.
    2) `(', `1', `)' -- macro tokens, by cb_lex_token.
    3) macro_end_arg.
    4) `1', `+' -- macro replacement tokens, by symdb_cpp_token.
    5) `(', `2', `)' -- macro tokens, by cb_lex_token.
    6) macro_end_arg.
    7) `2' -- macro replacement tokens, by symdb_cpp_token.
    8) macro_end_expand.

The thing I emphasized here is cb_lex_token is set by macro_start_expand
intern -- it isn't valid anytime. So
    buff = funlike_invocation_p (pfile, node, &pragma_buff,
    ...
    if (buff == NULL)
      {
    ...
      }
if macro_start_expand is moved to the clause block `buff != NULL', it's too
later to set cb_lex_token because funlike_invocation_p has read some macro
tokens.

Of course I can remove macro_end_arg totally, because from the sample, it's the
fact that macro tokens aren't always before any macro replacement tokens. But
macro_end_expand must be prepared to deal with cancel case.

BTW, currently it isn't necessary to my plugin to collect macro tokens, so if
gcc doesn't support collect macro token event, macro_start_expand and
macro_end_expand can be moved into enter_macro_context and _cpp_pop_context
individually.

Yunfeng

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

* Re: [PATCH 1/2] gcc symbol database
  2012-07-17  7:14             ` Yunfeng ZHANG
@ 2012-07-17  9:06               ` Dodji Seketeli
  2012-07-18  2:11                 ` Yunfeng ZHANG
  0 siblings, 1 reply; 18+ messages in thread
From: Dodji Seketeli @ 2012-07-17  9:06 UTC (permalink / raw)
  To: Yunfeng ZHANG; +Cc: gcc-patches, Joseph S. Myers, Dave Korn, Tom Tromey

Yunfeng ZHANG <zyf.zeroos@gmail.com> writes:

> Please allow me to resend former sample:
>     #define Z(a) a
>     #define Y Z
>     #define X(p) p + Y
>     X(1)(2);
> The flow is:
>     1) `X' -- leader macro token by macro_start_expand.
>     2) `(', `1', `)' -- macro tokens, by cb_lex_token.
>     3) macro_end_arg.
>     4) `1', `+' -- macro replacement tokens, by symdb_cpp_token.
>     5) `(', `2', `)' -- macro tokens, by cb_lex_token.
>     6) macro_end_arg.
>     7) `2' -- macro replacement tokens, by symdb_cpp_token.
>     8) macro_end_expand.
>
> The thing I emphasized here is cb_lex_token is set by macro_start_expand
> intern -- it isn't valid anytime.

It took me a couple of minutes to understand what you meant here, so
please let me re-phrase to make sure I got it.

You are saying that the callback function of the cb_lex_token event is
set by the callback function of the macro_start_expand event.

Is that correct?

> So
>     buff = funlike_invocation_p (pfile, node, &pragma_buff,
>     ...
>     if (buff == NULL)
>       {
>     ...
>       }
> if macro_start_expand is moved to the clause block `buff != NULL', it's too
> later to set cb_lex_token because funlike_invocation_p has read some macro
> tokens.

Then for function-like macros, you can move the call to
macro_start_expand into funlike_invocation_p, right before it calls
collect_args (collect_args is the function that reads the macro
arguments).

And this makes me wonder why you'd need the second parameter of
macro_start_expand (the token).  I believe you should have all the
information you need with the first, second, and last parameter.  As I
said in my previous email, you can get the file offset of the token in
your client code by doing 'file_offset = line + column'.  So that token
should not be needed.  Thus, calling macro_start_expand from inside
funlike_invocation_p once you are sure the expansion of the macro is
going to take place, is possible.

For non-function-like macros, you can call macro_start_expand after the block

      if (macro->fun_like)
	{

inside enter_macro_context.

> Of course I can remove macro_end_arg totally, because from the sample, it's the
> fact that macro tokens aren't always before any macro replacement tokens. But
> macro_end_expand must be prepared to deal with cancel case.

I still think that with the plan above, you don't need any cancel case
because macro_start_expand is going to be called only when we know the
macro is going to be expanded.

-- 
		Dodji

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

* Re: [PATCH 1/2] gcc symbol database
  2012-07-17  9:06               ` Dodji Seketeli
@ 2012-07-18  2:11                 ` Yunfeng ZHANG
  2012-07-18  8:04                   ` Dodji Seketeli
  0 siblings, 1 reply; 18+ messages in thread
From: Yunfeng ZHANG @ 2012-07-18  2:11 UTC (permalink / raw)
  To: Dodji Seketeli; +Cc: gcc-patches, Joseph S. Myers, Dave Korn, Tom Tromey

> It took me a couple of minutes to understand what you meant here, so
> please let me re-phrase to make sure I got it.
>
> You are saying that the callback function of the cb_lex_token event is
> set by the callback function of the macro_start_expand event.
>
> Is that correct?

Yes.

> And this makes me wonder why you'd need the second parameter of
> macro_start_expand (the token).  I believe you should have all the
> information you need with the first, second, and last parameter.  As I
> said in my previous email, you can get the file offset of the token in
> your client code by doing 'file_offset = line + column'.  So that token
> should not be needed.  Thus, calling macro_start_expand from inside
> funlike_invocation_p once you are sure the expansion of the macro is
> going to take place, is possible.

The only thing is the file-offset or source_location of the macro leader token.
I don't know how to get it when macro_start_expand is called in
funlike_invocation_p intern. The parameter `result' of enter_macro_context
doesn't be delivered down. And file_offset = sum(`all former
column_total_count' + current column_number'), so it can't be deduced from
current line_map + source_location desgin.

BTW, I can change my plugin to use line/column instead of fileoffset, there
ins't design limitation, only time.

Yunfeng

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

* Re: [PATCH 1/2] gcc symbol database
  2012-07-18  2:11                 ` Yunfeng ZHANG
@ 2012-07-18  8:04                   ` Dodji Seketeli
  2012-07-19  1:18                     ` Yunfeng ZHANG
  0 siblings, 1 reply; 18+ messages in thread
From: Dodji Seketeli @ 2012-07-18  8:04 UTC (permalink / raw)
  To: Yunfeng ZHANG; +Cc: gcc-patches, Joseph S. Myers, Dave Korn, Tom Tromey

Yunfeng ZHANG <zyf.zeroos@gmail.com> writes:

>> It took me a couple of minutes to understand what you meant here, so
>> please let me re-phrase to make sure I got it.
>>
>> You are saying that the callback function of the cb_lex_token event is
>> set by the callback function of the macro_start_expand event.
>>
>> Is that correct?
>
> Yes.

Thank you for making this clear.

>> And this makes me wonder why you'd need the second parameter of
>> macro_start_expand (the token).  I believe you should have all the
>> information you need with the first, second, and last parameter.  As I
>> said in my previous email, you can get the file offset of the token in
>> your client code by doing 'file_offset = line + column'.  So that token
>> should not be needed.  Thus, calling macro_start_expand from inside
>> funlike_invocation_p once you are sure the expansion of the macro is
>> going to take place, is possible.
>
> The only thing is the file-offset or source_location of the macro
> leader token.

To try to avoid confusion, I think what you call "source_location of the
macro leader token" is actually the spelling location of the macro.

> I don't know how to get it when macro_start_expand is called in
> funlike_invocation_p intern.

[...]

> BTW, I can change my plugin to use line/column instead of fileoffset, there
> ins't design limitation, only time.

I think you can add a new source_location parameter to
funlike_invocation_p function, and pass it the result->src_loc that you
need.

-- 
		Dodji

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

* Re: [PATCH 1/2] gcc symbol database
  2012-07-18  8:04                   ` Dodji Seketeli
@ 2012-07-19  1:18                     ` Yunfeng ZHANG
  2012-07-19  7:04                       ` Yunfeng ZHANG
  0 siblings, 1 reply; 18+ messages in thread
From: Yunfeng ZHANG @ 2012-07-19  1:18 UTC (permalink / raw)
  To: Dodji Seketeli; +Cc: gcc-patches, Joseph S. Myers, Dave Korn, Tom Tromey

To Dodji Seketeli:

Thanks for you check my patch, I will release it again later.

Yunfeng

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

* Re: [PATCH 1/2] gcc symbol database
  2012-07-19  1:18                     ` Yunfeng ZHANG
@ 2012-07-19  7:04                       ` Yunfeng ZHANG
  2012-07-19  8:06                         ` Dodji Seketeli
  0 siblings, 1 reply; 18+ messages in thread
From: Yunfeng ZHANG @ 2012-07-19  7:04 UTC (permalink / raw)
  To: Dodji Seketeli; +Cc: gcc-patches, Joseph S. Myers, Dave Korn, Tom Tromey

Hi Dodji Seketeli:
> This is what I was trying to tell you in my previous message, when I was
> saying:
>
>     > _cpp_pop_context is really the function that marks the end of a
>     > given macro expansion, especially when the predicate
>     > in_macro_expansion_p (introduced recently in trunk for gcc 4.8)
>     > returns true.

So which version I will worked on if I want to release new patch, 4.8 trunk?

Yunfeng

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

* Re: [PATCH 1/2] gcc symbol database
  2012-07-19  7:04                       ` Yunfeng ZHANG
@ 2012-07-19  8:06                         ` Dodji Seketeli
  2012-08-06  5:37                           ` Yunfeng ZHANG
  0 siblings, 1 reply; 18+ messages in thread
From: Dodji Seketeli @ 2012-07-19  8:06 UTC (permalink / raw)
  To: Yunfeng ZHANG; +Cc: gcc-patches, Joseph S. Myers, Dave Korn, Tom Tromey

Yunfeng ZHANG <zyf.zeroos@gmail.com> writes:

> Hi Dodji Seketeli:
>> This is what I was trying to tell you in my previous message, when I was
>> saying:
>>
>>     > _cpp_pop_context is really the function that marks the end of a
>>     > given macro expansion, especially when the predicate
>>     > in_macro_expansion_p (introduced recently in trunk for gcc 4.8)
>>     > returns true.
>
> So which version I will worked on if I want to release new patch, 4.8
> trunk?

Yes, please.  I think new development of this sort should happen in
trunk, as much as possible.

Thank you for your time.

-- 
		Dodji

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

* Re: [PATCH 1/2] gcc symbol database
  2012-07-19  8:06                         ` Dodji Seketeli
@ 2012-08-06  5:37                           ` Yunfeng ZHANG
  2012-08-13  6:44                             ` Dodji Seketeli
  0 siblings, 1 reply; 18+ messages in thread
From: Yunfeng ZHANG @ 2012-08-06  5:37 UTC (permalink / raw)
  To: Dodji Seketeli; +Cc: gcc-patches, Joseph S. Myers, Dave Korn, Tom Tromey

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

Hi Dodji Seketeli:
Sorry to commit the patch so later, it costed me several days to solve a my
careless when migrating cpp_token::file_offset to line/column, it seems new
callbacks following from your advice work well in my patch, especially with
in_macro_expansion_p. Please check them in attachment ChangeLog, libcpp.patch
and plugin.patch.
Sincerely               Yunfeng

[-- Attachment #2: ChangeLog --]
[-- Type: application/octet-stream, Size: 1648 bytes --]

ChangeLog
-------------------------
libcpp/
2012-08-06  Yunfeng ZHANG <zyf.zeroos@gmail.com>

      * include/cpplib.h (struct cpp_callbacks): Add new callbacks.
      macro_start_expand, macro_end_expand, start_directive, end_directive,
      lex_token.
      * directives.c (start_directive): Implement start_directive.
      (end_directive): Implement end_directive.
      * macro.c (enter_macro_context): Implement macro_start_expand.
      (funlike_invocation_p): Implement macro_start_expand. Take a cpp_token
      parameter.
      (_cpp_pop_context): Implement macro_end_expand.
      * lex.c (_cpp_lex_token): Implement lex_token.

gcc/
2012-08-06  Yunfeng ZHANG <zyf.zeroos@gmail.com>

     * plugin.def: New plugin events, from new cpp/c token is arrived to new
     definition notification.
     * plugin.c (register_callback): Handle new plugin events.
     (invoke_plugin_callbacks_full): Likewise.
     * doc/plugins.texi: Document new plugin events.

gcc/c/
2012-08-06  Yunfeng ZHANG <zyf.zeroos@gmail.com>
     * c-parser.c:
     (c_lex_one_token): Invoke PLUGIN_C_TOKEN callback.
     (c_parser_external_declaration): Invoke PLUGIN_EXTERN_DECL callback.
     (c_parser_declaration_or_fndef): Invoke PLUGIN_EXTERN_DECLSPECS,
     PLUGIN_EXTERN_VAR, PLUGIN_EXTERN_FUNC_OLD_PARAM, PLUGIN_EXTERN_FUNC
     callbacks.
     (c_parser_enum_specifier): Invoke PLUGIN_ENUMERATOR callback.
     (c_parser_postfix_expression_after_primary): Invoke PLUGIN_CALL_FUNCTION
     callback.

gcc/c-family/
2012-08-06  Yunfeng ZHANG <zyf.zeroos@gmail.com>
     * c-lex.c: Include plugin.h.
     (c_lex_with_flags): Invoke PLUGIN_CPP_TOKEN callback.

[-- Attachment #3: libcpp.patch --]
[-- Type: application/octet-stream, Size: 6994 bytes --]

Only in libcpp/: .svn
Only in libcpp/: ChangeLog
Only in libcpp/: Makefile.in
Only in libcpp/: aclocal.m4
Only in libcpp/: charset.c
Only in libcpp/: config.in
Only in libcpp/: configure
Only in libcpp/: configure.ac
Only in libcpp/: directives-only.c
diff -cpr .pc/symdb_enhance_libcpp/libcpp/directives.c libcpp/directives.c
*** .pc/symdb_enhance_libcpp/libcpp/directives.c	Wed Jul 25 10:57:16 2012
--- libcpp/directives.c	Wed Jul 25 10:57:31 2012
*************** start_directive (cpp_reader *pfile)
*** 275,280 ****
--- 275,283 ----
  
    /* Some handlers need the position of the # for diagnostics.  */
    pfile->directive_line = pfile->line_table->highest_line;
+ 
+   if (pfile->cb.start_directive)
+     pfile->cb.start_directive (pfile);
  }
  
  /* Called when leaving a directive, _Pragma or command-line directive.  */
*************** end_directive (cpp_reader *pfile, int sk
*** 309,314 ****
--- 312,320 ----
    pfile->state.in_expression = 0;
    pfile->state.angled_headers = 0;
    pfile->directive = 0;
+ 
+   if (pfile->cb.end_directive)
+     pfile->cb.end_directive (pfile);
  }
  
  /* Prepare to handle the directive in pfile->directive.  */
Only in libcpp/: errors.c
Only in libcpp/: expr.c
Only in libcpp/: files.c
Only in libcpp/: identifiers.c
Only in libcpp/include: .svn
Only in libcpp/include: cpp-id-data.h
diff -cpr .pc/symdb_enhance_libcpp/libcpp/include/cpplib.h libcpp/include/cpplib.h
*** .pc/symdb_enhance_libcpp/libcpp/include/cpplib.h	Wed Jul 25 10:57:16 2012
--- libcpp/include/cpplib.h	Wed Jul 25 10:57:31 2012
*************** struct cpp_callbacks
*** 526,531 ****
--- 526,548 ----
       be expanded.  */
    cpp_hashnode * (*macro_to_expand) (cpp_reader *, const cpp_token *);
  
+   /* The more powerful function extracts token than cpp_get_token. Later
+    * callbacks show it. */
+   void (*lex_token) (cpp_reader *, const cpp_token*);
+   /* The pair is called when gcc expands macro. Enable lex_token in
+    * macro_start_expand, you can catch all macro tokens. The pair can be called
+    * nested, and the second parameter of macro_end_expand notifies you whether
+    * macro is still expanding. */
+   void (*macro_start_expand) (cpp_reader *, const cpp_token *,
+ 		  const cpp_hashnode *);
+   void (*macro_end_expand) (cpp_reader *, bool);
+   /* The pair is called when cpp directive (starting from `#', such as
+    * `#define M', `#endif' etc) is encountered and reaches end. When enable
+    * lex_token in start_directive, the sequence is lex_token("define"),
+    * lex_token("M") ... */
+   void (*start_directive) (cpp_reader *);
+   void (*end_directive) (cpp_reader *);
+ 
    /* Called to emit a diagnostic.  This callback receives the
       translated message.  */
    bool (*error) (cpp_reader *, int, int, source_location, unsigned int,
Only in libcpp/include: cpplib.h.rej
Only in libcpp/include: line-map.h
Only in libcpp/include: mkdeps.h
Only in libcpp/include: symtab.h
Only in libcpp/: init.c
Only in libcpp/: internal.h
Only in libcpp/: internal.h.rej
diff -cpr .pc/symdb_enhance_libcpp/libcpp/lex.c libcpp/lex.c
*** .pc/symdb_enhance_libcpp/libcpp/lex.c	Wed Jul 25 10:25:36 2012
--- libcpp/lex.c	Wed Jul 25 10:58:27 2012
*************** _cpp_lex_token (cpp_reader *pfile)
*** 1972,1977 ****
--- 1972,1979 ----
  	}
        else
  	result = _cpp_lex_direct (pfile);
+     if (pfile->cb.lex_token)
+       pfile->cb.lex_token (pfile, result);
  
        if (result->flags & BOL)
  	{
Only in libcpp/: lex.c.rej
Only in libcpp/: line-map.c
diff -cpr .pc/symdb_enhance_libcpp/libcpp/macro.c libcpp/macro.c
*** .pc/symdb_enhance_libcpp/libcpp/macro.c	Wed Jul 25 10:57:16 2012
--- libcpp/macro.c	Wed Jul 25 10:57:31 2012
*************** static inline void tokens_buff_remove_la
*** 148,154 ****
  static void replace_args (cpp_reader *, cpp_hashnode *, cpp_macro *,
  			  macro_arg *, source_location);
  static _cpp_buff *funlike_invocation_p (cpp_reader *, cpp_hashnode *,
! 					_cpp_buff **, unsigned *);
  static bool create_iso_definition (cpp_reader *, cpp_macro *);
  
  /* #define directive parsing and handling.  */
--- 148,154 ----
  static void replace_args (cpp_reader *, cpp_hashnode *, cpp_macro *,
  			  macro_arg *, source_location);
  static _cpp_buff *funlike_invocation_p (cpp_reader *, cpp_hashnode *,
! 					_cpp_buff **, unsigned *, const cpp_token *);
  static bool create_iso_definition (cpp_reader *, cpp_macro *);
  
  /* #define directive parsing and handling.  */
*************** collect_args (cpp_reader *pfile, const c
*** 963,969 ****
     returned buffer.  */
  static _cpp_buff *
  funlike_invocation_p (cpp_reader *pfile, cpp_hashnode *node,
! 		      _cpp_buff **pragma_buff, unsigned *num_args)
  {
    const cpp_token *token, *padding = NULL;
  
--- 963,970 ----
     returned buffer.  */
  static _cpp_buff *
  funlike_invocation_p (cpp_reader *pfile, cpp_hashnode *node,
! 		      _cpp_buff **pragma_buff, unsigned *num_args,
! 		      const cpp_token *head)
  {
    const cpp_token *token, *padding = NULL;
  
*************** funlike_invocation_p (cpp_reader *pfile,
*** 980,985 ****
--- 981,988 ----
    if (token->type == CPP_OPEN_PAREN)
      {
        pfile->state.parsing_args = 2;
+       if (pfile->cb.macro_start_expand)
+         pfile->cb.macro_start_expand (pfile, head, node);
        return collect_args (pfile, node, pragma_buff, num_args);
      }
  
*************** enter_macro_context (cpp_reader *pfile, 
*** 1064,1070 ****
  	  pfile->keep_tokens++;
  	  pfile->state.parsing_args = 1;
  	  buff = funlike_invocation_p (pfile, node, &pragma_buff,
! 				       &num_args);
  	  pfile->state.parsing_args = 0;
  	  pfile->keep_tokens--;
  	  pfile->state.prevent_expansion--;
--- 1067,1073 ----
  	  pfile->keep_tokens++;
  	  pfile->state.parsing_args = 1;
  	  buff = funlike_invocation_p (pfile, node, &pragma_buff,
! 				       &num_args, result);
  	  pfile->state.parsing_args = 0;
  	  pfile->keep_tokens--;
  	  pfile->state.prevent_expansion--;
*************** enter_macro_context (cpp_reader *pfile, 
*** 1110,1115 ****
--- 1113,1120 ----
  
        if (macro->paramc == 0)
  	{
+       if (pfile->cb.macro_start_expand)
+         pfile->cb.macro_start_expand (pfile, result, node);
  	  if (CPP_OPTION (pfile, track_macro_expansion))
  	    {
  	      unsigned int i, count = macro->count;
*************** _cpp_pop_context (cpp_reader *pfile)
*** 2245,2250 ****
--- 2250,2257 ----
    /* decrease peak memory consumption by feeing the context.  */
    pfile->context->next = NULL;
    free (context);
+   if (pfile->cb.macro_end_expand)
+     pfile->cb.macro_end_expand (pfile, in_macro_expansion_p (pfile));
  }
  
  /* Return TRUE if we reached the end of the set of tokens stored in
Only in libcpp/: macro.c.rej
Only in libcpp/: makeucnid.c
Only in libcpp/: mkdeps.c
Only in libcpp/: pch.c
Only in libcpp/: po
Only in libcpp/: symtab.c
Only in libcpp/: system.h
Only in libcpp/: traditional.c
Only in libcpp/: ucnid.h
Only in libcpp/: ucnid.tab

[-- Attachment #4: plugin.patch --]
[-- Type: application/octet-stream, Size: 28235 bytes --]

Only in gcc/: .svn
Only in gcc/: ABOUT-GCC-NLS
Only in gcc/: BASE-VER
Only in gcc/: COPYING
Only in gcc/: COPYING.LIB
Only in gcc/: COPYING3
Only in gcc/: COPYING3.LIB
Only in gcc/: ChangeLog
Only in gcc/: ChangeLog-1997
Only in gcc/: ChangeLog-1998
Only in gcc/: ChangeLog-1999
Only in gcc/: ChangeLog-2000
Only in gcc/: ChangeLog-2001
Only in gcc/: ChangeLog-2002
Only in gcc/: ChangeLog-2003
Only in gcc/: ChangeLog-2004
Only in gcc/: ChangeLog-2005
Only in gcc/: ChangeLog-2006
Only in gcc/: ChangeLog-2007
Only in gcc/: ChangeLog-2008
Only in gcc/: ChangeLog-2009
Only in gcc/: ChangeLog-2010
Only in gcc/: ChangeLog-2011
Only in gcc/: ChangeLog.dataflow
Only in gcc/: ChangeLog.graphite
Only in gcc/: ChangeLog.lib
Only in gcc/: ChangeLog.ptr
Only in gcc/: ChangeLog.tree-ssa
Only in gcc/: ChangeLog.tuples
Only in gcc/: DATESTAMP
Only in gcc/: DEV-PHASE
Only in gcc/: FSFChangeLog
Only in gcc/: FSFChangeLog.10
Only in gcc/: FSFChangeLog.11
Only in gcc/: LANGUAGES
Only in gcc/: Makefile.in
Only in gcc/: ONEWS
Only in gcc/: README.Portability
Only in gcc/: acinclude.m4
Only in gcc/: aclocal.m4
Only in gcc/: ada
Only in gcc/: addresses.h
Only in gcc/: alias.c
Only in gcc/: alias.h
Only in gcc/: alloc-pool.c
Only in gcc/: alloc-pool.h
Only in gcc/: attribs.c
Only in gcc/: auto-inc-dec.c
Only in gcc/: basic-block.h
Only in gcc/: bb-reorder.c
Only in gcc/: bb-reorder.h
Only in gcc/: bitmap.c
Only in gcc/: bitmap.h
Only in gcc/: bt-load.c
Only in gcc/: builtin-attrs.def
Only in gcc/: builtin-types.def
Only in gcc/: builtins.c
Only in gcc/: builtins.def
Only in gcc/: builtins.h
Only in gcc/c: .svn
Only in gcc/c: ChangeLog
Only in gcc/c: Make-lang.in
Only in gcc/c: c-aux-info.c
Only in gcc/c: c-convert.c
Only in gcc/c: c-decl.c
Only in gcc/c: c-errors.c
Only in gcc/c: c-lang.c
Only in gcc/c: c-lang.h
Only in gcc/c: c-objc-common.c
Only in gcc/c: c-objc-common.h
diff -cpr .pc/symdb_enhance_plugin/gcc/c/c-parser.c gcc/c/c-parser.c
*** .pc/symdb_enhance_plugin/gcc/c/c-parser.c	Wed Jul 25 10:57:16 2012
--- gcc/c/c-parser.c	Wed Jul 25 10:58:59 2012
*************** c_lex_one_token (c_parser *parser, c_tok
*** 387,392 ****
--- 387,393 ----
        break;
      }
    timevar_pop (TV_LEX);
+   invoke_plugin_callbacks (PLUGIN_C_TOKEN, token);
  }
  
  /* Return a pointer to the next token from PARSER, reading it in if
*************** c_parser_external_declaration (c_parser 
*** 1359,1364 ****
--- 1360,1366 ----
  	 an @interface or @protocol with prefix attributes).  We can
  	 only tell which after parsing the declaration specifiers, if
  	 any, and the first declarator.  */
+       invoke_plugin_callbacks (PLUGIN_EXTERN_DECL, NULL);
        c_parser_declaration_or_fndef (parser, true, true, true, false, true, NULL);
        break;
      }
*************** c_parser_declaration_or_fndef (c_parser 
*** 1487,1492 ****
--- 1489,1499 ----
        return;
      }
    finish_declspecs (specs);
+   {
+     void* pair[2]; pair[0] = specs; pair[1] = (void*) parser->tokens_avail;
+     if (!nested)
+       invoke_plugin_callbacks (PLUGIN_EXTERN_DECLSPECS, pair);
+   }
    if (c_parser_next_token_is (parser, CPP_SEMICOLON))
      {
        if (empty_ok)
*************** c_parser_declaration_or_fndef (c_parser 
*** 1621,1626 ****
--- 1628,1638 ----
  	{
  	  tree asm_name = NULL_TREE;
  	  tree postfix_attrs = NULL_TREE;
+ 	  {
+ 	    void* pair[2]; pair[0] = specs; pair[1] = declarator;
+         if (!nested)
+           invoke_plugin_callbacks (PLUGIN_EXTERN_VAR, pair);
+ 	  }
  	  if (!diagnosed_no_specs && !specs->declspecs_seen_p)
  	    {
  	      diagnosed_no_specs = true;
*************** c_parser_declaration_or_fndef (c_parser 
*** 1747,1757 ****
--- 1759,1773 ----
  	 declarator with a nonempty identifier list in a definition;
  	 and postfix attributes have never been accepted here in
  	 function definitions either.  */
+       if (!nested)
+         invoke_plugin_callbacks (PLUGIN_EXTERN_FUNC_OLD_PARAM, NULL);
        while (c_parser_next_token_is_not (parser, CPP_EOF)
  	     && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
  	c_parser_declaration_or_fndef (parser, false, false, false,
  				       true, false, NULL);
        store_parm_decls ();
+       if (!nested)
+         invoke_plugin_callbacks (PLUGIN_EXTERN_FUNC, declarator);
        DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
  	= c_parser_peek_token (parser)->location;
        fnbody = c_parser_compound_statement (parser);
*************** c_parser_enum_specifier (c_parser *parse
*** 2267,2272 ****
--- 2283,2289 ----
  	    }
  	  token = c_parser_peek_token (parser);
  	  enum_id = token->value;
+       invoke_plugin_callbacks (PLUGIN_ENUMERATOR, enum_id);
  	  /* Set the location in case we create a decl now.  */
  	  c_parser_set_source_position_from_token (token);
  	  decl_loc = value_loc = token->location;
*************** c_parser_postfix_expression_after_primar
*** 6876,6881 ****
--- 6893,6899 ----
  	  break;
  	case CPP_OPEN_PAREN:
  	  /* Function call.  */
+       invoke_plugin_callbacks (PLUGIN_CALL_FUNCTION, expr.value);
  	  c_parser_consume_token (parser);
  	  if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
  	    exprlist = NULL;
Only in gcc/c: c-tree.h
Only in gcc/c: c-typeck.c
Only in gcc/c: config-lang.in
Only in gcc/c: gccspec.c
Only in gcc/c-family: .svn
Only in gcc/c-family: ChangeLog
Only in gcc/c-family: c-ada-spec.c
Only in gcc/c-family: c-ada-spec.h
Only in gcc/c-family: c-common.c
Only in gcc/c-family: c-common.def
Only in gcc/c-family: c-common.h
Only in gcc/c-family: c-common.h.rej
Only in gcc/c-family: c-cppbuiltin.c
Only in gcc/c-family: c-dump.c
Only in gcc/c-family: c-format.c
Only in gcc/c-family: c-format.h
Only in gcc/c-family: c-gimplify.c
diff -cpr .pc/symdb_enhance_plugin/gcc/c-family/c-lex.c gcc/c-family/c-lex.c
*** .pc/symdb_enhance_plugin/gcc/c-family/c-lex.c	Wed Jul 25 10:57:16 2012
--- gcc/c-family/c-lex.c	Wed Jul 25 10:58:59 2012
*************** along with GCC; see the file COPYING3.  
*** 35,40 ****
--- 35,41 ----
  #include "splay-tree.h"
  #include "debug.h"
  #include "target.h"
+ #include "plugin.h"
  
  /* We may keep statistics about how long which files took to compile.  */
  static int header_time, body_time;
*************** c_lex_with_flags (tree *value, location_
*** 379,384 ****
--- 380,386 ----
  	    case CPP_STRING32:
  	    case CPP_UTF8STRING:
  	      type = lex_string (tok, value, true, true);
+ 		  tok = NULL;
  	      break;
  
  	    case CPP_NAME:
*************** c_lex_with_flags (tree *value, location_
*** 480,485 ****
--- 482,488 ----
  	{
  	  type = lex_string (tok, value, false,
  			     (lex_flags & C_LEX_STRING_NO_TRANSLATE) == 0);
+ 	  tok = NULL;
  	  break;
  	}
        *value = build_string (tok->val.str.len, (const char *) tok->val.str.text);
*************** c_lex_with_flags (tree *value, location_
*** 514,519 ****
--- 517,523 ----
      }
  
    timevar_pop (TV_CPP);
+   invoke_plugin_callbacks (PLUGIN_CPP_TOKEN, tok);
  
    return type;
  }
Only in gcc/c-family: c-objc.h
Only in gcc/c-family: c-omp.c
Only in gcc/c-family: c-opts.c
Only in gcc/c-family: c-pch.c
Only in gcc/c-family: c-ppoutput.c
Only in gcc/c-family: c-pragma.c
Only in gcc/c-family: c-pragma.h
Only in gcc/c-family: c-pretty-print.c
Only in gcc/c-family: c-pretty-print.h
Only in gcc/c-family: c-semantics.c
Only in gcc/c-family: c-target-def.h
Only in gcc/c-family: c-target.def
Only in gcc/c-family: c-target.h
Only in gcc/c-family: c.opt
Only in gcc/c-family: cppspec.c
Only in gcc/c-family: stub-objc.c
Only in gcc/: caller-save.c
Only in gcc/: calls.c
Only in gcc/: cfg-flags.def
Only in gcc/: cfg.c
Only in gcc/: cfganal.c
Only in gcc/: cfgbuild.c
Only in gcc/: cfgcleanup.c
Only in gcc/: cfgexpand.c
Only in gcc/: cfghooks.c
Only in gcc/: cfghooks.h
Only in gcc/: cfgloop.c
Only in gcc/: cfgloop.h
Only in gcc/: cfgloopanal.c
Only in gcc/: cfgloopmanip.c
Only in gcc/: cfgrtl.c
Only in gcc/: cgraph.c
Only in gcc/: cgraph.h
Only in gcc/: cgraphbuild.c
Only in gcc/: cgraphclones.c
Only in gcc/: cgraphunit.c
Only in gcc/: cif-code.def
Only in gcc/: collect2-aix.c
Only in gcc/: collect2-aix.h
Only in gcc/: collect2.c
Only in gcc/: collect2.h
Only in gcc/: combine-stack-adj.c
Only in gcc/: combine.c
Only in gcc/: common
Only in gcc/: common.opt
Only in gcc/: compare-elim.c
Only in gcc/: conditions.h
Only in gcc/: config
Only in gcc/: config.build
Only in gcc/: config.gcc
Only in gcc/: config.host
Only in gcc/: config.in
Only in gcc/: configure
Only in gcc/: configure.ac
Only in gcc/: convert.c
Only in gcc/: convert.h
Only in gcc/: coretypes.h
Only in gcc/: coverage.c
Only in gcc/: coverage.h
Only in gcc/: cp
Only in gcc/: cppbuiltin.c
Only in gcc/: cppbuiltin.h
Only in gcc/: cppdefault.c
Only in gcc/: cppdefault.h
Only in gcc/: cprop.c
Only in gcc/: cse.c
Only in gcc/: cselib.c
Only in gcc/: cselib.h
Only in gcc/: cstamp-h.in
Only in gcc/: data-streamer-in.c
Only in gcc/: data-streamer-out.c
Only in gcc/: data-streamer.c
Only in gcc/: data-streamer.h
Only in gcc/: dbgcnt.c
Only in gcc/: dbgcnt.def
Only in gcc/: dbgcnt.h
Only in gcc/: dbxout.c
Only in gcc/: dbxout.h
Only in gcc/: dce.c
Only in gcc/: dce.h
Only in gcc/: ddg.c
Only in gcc/: ddg.h
Only in gcc/: debug.c
Only in gcc/: debug.h
Only in gcc/: defaults.h
Only in gcc/: df-core.c
Only in gcc/: df-problems.c
Only in gcc/: df-scan.c
Only in gcc/: df.h
Only in gcc/: dfp.c
Only in gcc/: dfp.h
Only in gcc/: diagnostic-core.h
Only in gcc/: diagnostic.c
Only in gcc/: diagnostic.def
Only in gcc/: diagnostic.h
Only in gcc/doc: .svn
Only in gcc/doc: arm-neon-intrinsics.texi
Only in gcc/doc: avr-mmcu.texi
Only in gcc/doc: bugreport.texi
Only in gcc/doc: cfg.texi
Only in gcc/doc: collect2.texi
Only in gcc/doc: compat.texi
Only in gcc/doc: configfiles.texi
Only in gcc/doc: configterms.texi
Only in gcc/doc: contrib.texi
Only in gcc/doc: contribute.texi
Only in gcc/doc: cpp.texi
Only in gcc/doc: cppenv.texi
Only in gcc/doc: cppinternals.texi
Only in gcc/doc: cppopts.texi
Only in gcc/doc: extend.texi
Only in gcc/doc: fragments.texi
Only in gcc/doc: frontends.texi
Only in gcc/doc: gcc.texi
Only in gcc/doc: gccint.texi
Only in gcc/doc: gcov.texi
Only in gcc/doc: generic.texi
Only in gcc/doc: gimple.texi
Only in gcc/doc: gnu.texi
Only in gcc/doc: gty.texi
Only in gcc/doc: headerdirs.texi
Only in gcc/doc: hostconfig.texi
Only in gcc/doc: implement-c.texi
Only in gcc/doc: implement-cxx.texi
Only in gcc/doc: include
Only in gcc/doc: install-old.texi
Only in gcc/doc: install.texi
Only in gcc/doc: install.texi2html
Only in gcc/doc: interface.texi
Only in gcc/doc: invoke.texi
Only in gcc/doc: languages.texi
Only in gcc/doc: libgcc.texi
Only in gcc/doc: loop.texi
Only in gcc/doc: lto.texi
Only in gcc/doc: makefile.texi
Only in gcc/doc: md.texi
Only in gcc/doc: objc.texi
Only in gcc/doc: options.texi
Only in gcc/doc: passes.texi
diff -cpr .pc/symdb_enhance_plugin/gcc/doc/plugins.texi gcc/doc/plugins.texi
*** .pc/symdb_enhance_plugin/gcc/doc/plugins.texi	Wed Jul 25 10:57:16 2012
--- gcc/doc/plugins.texi	Wed Jul 25 10:58:59 2012
*************** enum plugin_event
*** 184,189 ****
--- 184,206 ----
    PLUGIN_EARLY_GIMPLE_PASSES_END,
    /* Called when a pass is first instantiated.  */
    PLUGIN_NEW_PASS,
+   PLUGIN_CPP_TOKEN,                /* Called when GCC gets a cpp token. */
+   PLUGIN_C_TOKEN,                  /* Called when GCC gets a c token. */
+   /* An extern declaration (file-scope) is encounted. */
+   PLUGIN_EXTERN_DECL,
+   /* Cooperate PLUGIN_EXTERN_FUNC to parse a function with old-style parameter
+    * declaration. */
+   PLUGIN_EXTERN_FUNC_OLD_PARAM,
+   /* An extern function definition is parsed. */
+   PLUGIN_EXTERN_FUNC,
+   /* An extern variable definition is parsed. */
+   PLUGIN_EXTERN_VAR,
+   /* An extern declaration specifier definition is parsed. */
+   PLUGIN_EXTERN_DECLSPECS,
+   /* A function is called. */
+   PLUGIN_CALL_FUNCTION,
+   /* An enumerator is parsed. */
+   PLUGIN_ENUMERATOR,
  
    PLUGIN_EVENT_FIRST_DYNAMIC    /* Dummy event used for indexing callback
                                     array.  */
Only in gcc/doc: portability.texi
Only in gcc/doc: rtl.texi
Only in gcc/doc: service.texi
Only in gcc/doc: sourcebuild.texi
Only in gcc/doc: standards.texi
Only in gcc/doc: tm.texi
Only in gcc/doc: tm.texi.in
Only in gcc/doc: tree-ssa.texi
Only in gcc/doc: trouble.texi
Only in gcc/: dojump.c
Only in gcc/: dominance.c
Only in gcc/: domwalk.c
Only in gcc/: domwalk.h
Only in gcc/: double-int.c
Only in gcc/: double-int.h
Only in gcc/: dse.c
Only in gcc/: dumpfile.h
Only in gcc/: dwarf2asm.c
Only in gcc/: dwarf2asm.h
Only in gcc/: dwarf2cfi.c
Only in gcc/: dwarf2out.c
Only in gcc/: dwarf2out.h
Only in gcc/: ebitmap.c
Only in gcc/: ebitmap.h
Only in gcc/: emit-rtl.c
Only in gcc/: emit-rtl.h
Only in gcc/: errors.c
Only in gcc/: errors.h
Only in gcc/: et-forest.c
Only in gcc/: et-forest.h
Only in gcc/: except.c
Only in gcc/: except.h
Only in gcc/: exec-tool.in
Only in gcc/: explow.c
Only in gcc/: expmed.c
Only in gcc/: expmed.h
Only in gcc/: expr.c
Only in gcc/: expr.h
Only in gcc/: final.c
Only in gcc/: fixed-value.c
Only in gcc/: fixed-value.h
Only in gcc/: flag-types.h
Only in gcc/: flags.h
Only in gcc/: fold-const.c
Only in gcc/: fortran
Only in gcc/: fp-test.c
Only in gcc/: function.c
Only in gcc/: function.h
Only in gcc/: fwprop.c
Only in gcc/: gcc-ar.c
Only in gcc/: gcc-plugin.h
Only in gcc/: gcc.c
Only in gcc/: gcc.h
Only in gcc/: gcov-dump.c
Only in gcc/: gcov-io.c
Only in gcc/: gcov-io.h
Only in gcc/: gcov-iov.c
Only in gcc/: gcov.c
Only in gcc/: gcse.c
Only in gcc/: gcse.h
Only in gcc/: gdbinit.in
Only in gcc/: genattr-common.c
Only in gcc/: genattr.c
Only in gcc/: genattrtab.c
Only in gcc/: genautomata.c
Only in gcc/: gencheck.c
Only in gcc/: genchecksum.c
Only in gcc/: gencodes.c
Only in gcc/: genconditions.c
Only in gcc/: genconfig.c
Only in gcc/: genconstants.c
Only in gcc/: genemit.c
Only in gcc/: genenums.c
Only in gcc/: genextract.c
Only in gcc/: genflags.c
Only in gcc/: gengenrtl.c
Only in gcc/: gengtype-lex.l
Only in gcc/: gengtype-parse.c
Only in gcc/: gengtype-state.c
Only in gcc/: gengtype.c
Only in gcc/: gengtype.h
Only in gcc/: genhooks.c
Only in gcc/: genmddeps.c
Only in gcc/: genmodes.c
Only in gcc/: genmultilib
Only in gcc/: genopinit.c
Only in gcc/: genoutput.c
Only in gcc/: genpeep.c
Only in gcc/: genpreds.c
Only in gcc/: genrecog.c
Only in gcc/: gensupport.c
Only in gcc/: gensupport.h
Only in gcc/: ggc-common.c
Only in gcc/: ggc-internal.h
Only in gcc/: ggc-none.c
Only in gcc/: ggc-page.c
Only in gcc/: ggc-zone.c
Only in gcc/: ggc.h
Only in gcc/: gimple-fold.c
Only in gcc/: gimple-fold.h
Only in gcc/: gimple-iterator.c
Only in gcc/: gimple-low.c
Only in gcc/: gimple-pretty-print.c
Only in gcc/: gimple-pretty-print.h
Only in gcc/: gimple-ssa-strength-reduction.c
Only in gcc/: gimple-streamer-in.c
Only in gcc/: gimple-streamer-out.c
Only in gcc/: gimple-streamer.h
Only in gcc/: gimple.c
Only in gcc/: gimple.def
Only in gcc/: gimple.h
Only in gcc/: gimplify.c
Only in gcc/: ginclude
Only in gcc/: glimits.h
Only in gcc/: go
Only in gcc/: godump.c
Only in gcc/: graph.c
Only in gcc/: graph.h
Only in gcc/: graphds.c
Only in gcc/: graphds.h
Only in gcc/: graphite-blocking.c
Only in gcc/: graphite-clast-to-gimple.c
Only in gcc/: graphite-clast-to-gimple.h
Only in gcc/: graphite-dependences.c
Only in gcc/: graphite-interchange.c
Only in gcc/: graphite-optimize-isl.c
Only in gcc/: graphite-poly.c
Only in gcc/: graphite-poly.h
Only in gcc/: graphite-scop-detection.c
Only in gcc/: graphite-scop-detection.h
Only in gcc/: graphite-sese-to-poly.c
Only in gcc/: graphite-sese-to-poly.h
Only in gcc/: graphite.c
Only in gcc/: gsstruct.def
Only in gcc/: gstab.h
Only in gcc/: gsyms.h
Only in gcc/: gsyslimits.h
Only in gcc/: gtm-builtins.def
Only in gcc/: haifa-sched.c
Only in gcc/: hard-reg-set.h
Only in gcc/: highlev-plugin-common.h
Only in gcc/: hooks.c
Only in gcc/: hooks.h
Only in gcc/: host-default.c
Only in gcc/: hosthooks-def.h
Only in gcc/: hosthooks.h
Only in gcc/: hw-doloop.c
Only in gcc/: hw-doloop.h
Only in gcc/: hwint.c
Only in gcc/: hwint.h
Only in gcc/: ifcvt.c
Only in gcc/: incpath.c
Only in gcc/: incpath.h
Only in gcc/: init-regs.c
Only in gcc/: input.c
Only in gcc/: input.h
Only in gcc/: insn-addr.h
Only in gcc/: insn-notes.def
Only in gcc/: internal-fn.c
Only in gcc/: internal-fn.def
Only in gcc/: internal-fn.h
Only in gcc/: intl.c
Only in gcc/: intl.h
Only in gcc/: ipa-cp.c
Only in gcc/: ipa-inline-analysis.c
Only in gcc/: ipa-inline-transform.c
Only in gcc/: ipa-inline.c
Only in gcc/: ipa-inline.h
Only in gcc/: ipa-prop.c
Only in gcc/: ipa-prop.h
Only in gcc/: ipa-pure-const.c
Only in gcc/: ipa-ref-inline.h
Only in gcc/: ipa-ref.c
Only in gcc/: ipa-ref.h
Only in gcc/: ipa-reference.c
Only in gcc/: ipa-reference.h
Only in gcc/: ipa-split.c
Only in gcc/: ipa-utils.c
Only in gcc/: ipa-utils.h
Only in gcc/: ipa.c
Only in gcc/: ira-build.c
Only in gcc/: ira-color.c
Only in gcc/: ira-conflicts.c
Only in gcc/: ira-costs.c
Only in gcc/: ira-emit.c
Only in gcc/: ira-int.h
Only in gcc/: ira-lives.c
Only in gcc/: ira.c
Only in gcc/: ira.h
Only in gcc/: java
Only in gcc/: jump.c
Only in gcc/: langhooks-def.h
Only in gcc/: langhooks.c
Only in gcc/: langhooks.h
Only in gcc/: lcm.c
Only in gcc/: libfuncs.h
Only in gcc/: limitx.h
Only in gcc/: limity.h
Only in gcc/: lists.c
Only in gcc/: loop-doloop.c
Only in gcc/: loop-init.c
Only in gcc/: loop-invariant.c
Only in gcc/: loop-iv.c
Only in gcc/: loop-unroll.c
Only in gcc/: loop-unswitch.c
Only in gcc/: lower-subreg.c
Only in gcc/: lower-subreg.h
Only in gcc/: lto
Only in gcc/: lto-cgraph.c
Only in gcc/: lto-compress.c
Only in gcc/: lto-compress.h
Only in gcc/: lto-opts.c
Only in gcc/: lto-section-in.c
Only in gcc/: lto-section-out.c
Only in gcc/: lto-streamer-in.c
Only in gcc/: lto-streamer-out.c
Only in gcc/: lto-streamer.c
Only in gcc/: lto-streamer.h
Only in gcc/: lto-symtab.c
Only in gcc/: lto-wrapper.c
Only in gcc/: machmode.def
Only in gcc/: machmode.h
Only in gcc/: main.c
Only in gcc/: matrix-reorg.c
Only in gcc/: mcf.c
Only in gcc/: mkconfig.sh
Only in gcc/: mode-classes.def
Only in gcc/: mode-switching.c
Only in gcc/: modulo-sched.c
Only in gcc/: objc
Only in gcc/: objcp
Only in gcc/: omega.c
Only in gcc/: omega.h
Only in gcc/: omp-builtins.def
Only in gcc/: omp-low.c
Only in gcc/: opt-functions.awk
Only in gcc/: opt-gather.awk
Only in gcc/: opt-include.awk
Only in gcc/: opt-read.awk
Only in gcc/: optabs.c
Only in gcc/: optabs.h
Only in gcc/: optc-gen.awk
Only in gcc/: optc-save-gen.awk
Only in gcc/: opth-gen.awk
Only in gcc/: opts-common.c
Only in gcc/: opts-diagnostic.h
Only in gcc/: opts-global.c
Only in gcc/: opts.c
Only in gcc/: opts.h
Only in gcc/: output.h
Only in gcc/: params.c
Only in gcc/: params.def
Only in gcc/: params.h
Only in gcc/: passes.c
diff -cpr .pc/symdb_enhance_plugin/gcc/plugin.c gcc/plugin.c
*** .pc/symdb_enhance_plugin/gcc/plugin.c	Wed Jul 25 10:57:16 2012
--- gcc/plugin.c	Wed Jul 25 10:58:59 2012
*************** register_callback (const char *plugin_na
*** 438,443 ****
--- 438,452 ----
        case PLUGIN_EARLY_GIMPLE_PASSES_START:
        case PLUGIN_EARLY_GIMPLE_PASSES_END:
        case PLUGIN_NEW_PASS:
+       case PLUGIN_CPP_TOKEN:
+       case PLUGIN_C_TOKEN:
+       case PLUGIN_EXTERN_DECL:
+       case PLUGIN_EXTERN_FUNC_OLD_PARAM:
+       case PLUGIN_EXTERN_FUNC:
+       case PLUGIN_EXTERN_VAR:
+       case PLUGIN_EXTERN_DECLSPECS:
+       case PLUGIN_CALL_FUNCTION:
+       case PLUGIN_ENUMERATOR:
          {
            struct callback_info *new_callback;
            if (!callback)
*************** invoke_plugin_callbacks_full (int event,
*** 515,520 ****
--- 524,538 ----
        case PLUGIN_EARLY_GIMPLE_PASSES_START:
        case PLUGIN_EARLY_GIMPLE_PASSES_END:
        case PLUGIN_NEW_PASS:
+       case PLUGIN_CPP_TOKEN:
+       case PLUGIN_C_TOKEN:
+       case PLUGIN_EXTERN_DECL:
+       case PLUGIN_EXTERN_FUNC_OLD_PARAM:
+       case PLUGIN_EXTERN_FUNC:
+       case PLUGIN_EXTERN_VAR:
+       case PLUGIN_EXTERN_DECLSPECS:
+       case PLUGIN_CALL_FUNCTION:
+       case PLUGIN_ENUMERATOR:
          {
            /* Iterate over every callback registered with this event and
               call it.  */
diff -cpr .pc/symdb_enhance_plugin/gcc/plugin.def gcc/plugin.def
*** .pc/symdb_enhance_plugin/gcc/plugin.def	Wed Jul 25 10:57:16 2012
--- gcc/plugin.def	Wed Jul 25 10:58:59 2012
*************** DEFEVENT (PLUGIN_EARLY_GIMPLE_PASSES_END
*** 92,97 ****
--- 92,125 ----
  /* Called when a pass is first instantiated.  */
  DEFEVENT (PLUGIN_NEW_PASS)
  
+ /* Called when a cpp token is extracted.  */
+ DEFEVENT (PLUGIN_CPP_TOKEN)
+ 
+ /* Called when a c token is extracted.  */
+ DEFEVENT (PLUGIN_C_TOKEN)
+ 
+ /* An extern declaration (file-scope) is encounted. */
+ DEFEVENT (PLUGIN_EXTERN_DECL)
+ 
+ /* Cooperate PLUGIN_EXTERN_FUNC to parse a function with old-style parameter
+  * declaration. */
+ DEFEVENT (PLUGIN_EXTERN_FUNC_OLD_PARAM)
+ 
+ /* Called when an extern function definition is parsed. */
+ DEFEVENT (PLUGIN_EXTERN_FUNC)
+ 
+ /* Called when an extern variable definition is parsed. */
+ DEFEVENT (PLUGIN_EXTERN_VAR)
+ 
+ /* An extern declaration specifier definition is parsed. */
+ DEFEVENT (PLUGIN_EXTERN_DECLSPECS)
+ 
+ /* A function is called. */
+ DEFEVENT (PLUGIN_CALL_FUNCTION)
+ 
+ /* Called when an enumerator is parsed. */
+ DEFEVENT (PLUGIN_ENUMERATOR)
+ 
  /* After the hard-coded events above, plugins can dynamically allocate events
     at run time.
     PLUGIN_EVENT_FIRST_DYNAMIC only appears as last enum element.  */
Only in gcc/: plugin.h
Only in gcc/: po
Only in gcc/: pointer-set.c
Only in gcc/: pointer-set.h
Only in gcc/: postreload-gcse.c
Only in gcc/: postreload.c
Only in gcc/: predict.c
Only in gcc/: predict.def
Only in gcc/: predict.h
Only in gcc/: prefix.c
Only in gcc/: prefix.h
Only in gcc/: pretty-print.c
Only in gcc/: pretty-print.h
Only in gcc/: print-rtl.c
Only in gcc/: print-tree.c
Only in gcc/: profile.c
Only in gcc/: profile.h
Only in gcc/: read-md.c
Only in gcc/: read-md.h
Only in gcc/: read-rtl.c
Only in gcc/: real.c
Only in gcc/: real.h
Only in gcc/: realmpfr.c
Only in gcc/: realmpfr.h
Only in gcc/: recog.c
Only in gcc/: recog.h
Only in gcc/: ree.c
Only in gcc/: reg-notes.def
Only in gcc/: reg-stack.c
Only in gcc/: regcprop.c
Only in gcc/: reginfo.c
Only in gcc/: regmove.c
Only in gcc/: regrename.c
Only in gcc/: regrename.h
Only in gcc/: regs.h
Only in gcc/: regset.h
Only in gcc/: regstat.c
Only in gcc/: reload.c
Only in gcc/: reload.h
Only in gcc/: reload1.c
Only in gcc/: reorg.c
Only in gcc/: resource.c
Only in gcc/: resource.h
Only in gcc/: rtl-error.c
Only in gcc/: rtl-error.h
Only in gcc/: rtl.c
Only in gcc/: rtl.def
Only in gcc/: rtl.h
Only in gcc/: rtlanal.c
Only in gcc/: rtlhooks-def.h
Only in gcc/: rtlhooks.c
Only in gcc/: sbitmap.c
Only in gcc/: sbitmap.h
Only in gcc/: sched-deps.c
Only in gcc/: sched-ebb.c
Only in gcc/: sched-int.h
Only in gcc/: sched-rgn.c
Only in gcc/: sched-vis.c
Only in gcc/: sdbout.c
Only in gcc/: sdbout.h
Only in gcc/: sel-sched-dump.c
Only in gcc/: sel-sched-dump.h
Only in gcc/: sel-sched-ir.c
Only in gcc/: sel-sched-ir.h
Only in gcc/: sel-sched.c
Only in gcc/: sel-sched.h
Only in gcc/: sese.c
Only in gcc/: sese.h
Only in gcc/: simplify-rtx.c
Only in gcc/: sparseset.c
Only in gcc/: sparseset.h
Only in gcc/: sreal.c
Only in gcc/: sreal.h
Only in gcc/: ssaexpand.h
Only in gcc/: stab.def
Only in gcc/: stack-ptr-mod.c
Only in gcc/: statistics.c
Only in gcc/: statistics.h
Only in gcc/: stmt.c
Only in gcc/: stor-layout.c
Only in gcc/: store-motion.c
Only in gcc/: streamer-hooks.c
Only in gcc/: streamer-hooks.h
Only in gcc/: stringpool.c
Only in gcc/: symtab.c
Only in gcc/: sync-builtins.def
Only in gcc/: system.h
Only in gcc/: target-def.h
Only in gcc/: target-globals.c
Only in gcc/: target-globals.h
Only in gcc/: target-hooks-macros.h
Only in gcc/: target.def
Only in gcc/: target.h
Only in gcc/: targhooks.c
Only in gcc/: targhooks.h
Only in gcc/: testsuite
Only in gcc/: timevar.c
Only in gcc/: timevar.def
Only in gcc/: timevar.h
Only in gcc/: tlink.c
Only in gcc/: toplev.c
Only in gcc/: toplev.h
Only in gcc/: tracer.c
Only in gcc/: trans-mem.c
Only in gcc/: trans-mem.h
Only in gcc/: tree-affine.c
Only in gcc/: tree-affine.h
Only in gcc/: tree-browser.c
Only in gcc/: tree-browser.def
Only in gcc/: tree-call-cdce.c
Only in gcc/: tree-cfg.c
Only in gcc/: tree-cfgcleanup.c
Only in gcc/: tree-chrec.c
Only in gcc/: tree-chrec.h
Only in gcc/: tree-complex.c
Only in gcc/: tree-data-ref.c
Only in gcc/: tree-data-ref.h
Only in gcc/: tree-dfa.c
Only in gcc/: tree-diagnostic.c
Only in gcc/: tree-diagnostic.h
Only in gcc/: tree-dump.c
Only in gcc/: tree-dump.h
Only in gcc/: tree-eh.c
Only in gcc/: tree-emutls.c
Only in gcc/: tree-flow-inline.h
Only in gcc/: tree-flow.h
Only in gcc/: tree-if-conv.c
Only in gcc/: tree-inline.c
Only in gcc/: tree-inline.h
Only in gcc/: tree-into-ssa.c
Only in gcc/: tree-iterator.c
Only in gcc/: tree-iterator.h
Only in gcc/: tree-loop-distribution.c
Only in gcc/: tree-mudflap.c
Only in gcc/: tree-mudflap.h
Only in gcc/: tree-nested.c
Only in gcc/: tree-nomudflap.c
Only in gcc/: tree-nrv.c
Only in gcc/: tree-object-size.c
Only in gcc/: tree-optimize.c
Only in gcc/: tree-outof-ssa.c
Only in gcc/: tree-parloops.c
Only in gcc/: tree-pass.h
Only in gcc/: tree-phinodes.c
Only in gcc/: tree-predcom.c
Only in gcc/: tree-pretty-print.c
Only in gcc/: tree-pretty-print.h
Only in gcc/: tree-profile.c
Only in gcc/: tree-scalar-evolution.c
Only in gcc/: tree-scalar-evolution.h
Only in gcc/: tree-sra.c
Only in gcc/: tree-ssa-address.c
Only in gcc/: tree-ssa-alias.c
Only in gcc/: tree-ssa-alias.h
Only in gcc/: tree-ssa-ccp.c
Only in gcc/: tree-ssa-coalesce.c
Only in gcc/: tree-ssa-copy.c
Only in gcc/: tree-ssa-copyrename.c
Only in gcc/: tree-ssa-dce.c
Only in gcc/: tree-ssa-dom.c
Only in gcc/: tree-ssa-dse.c
Only in gcc/: tree-ssa-forwprop.c
Only in gcc/: tree-ssa-ifcombine.c
Only in gcc/: tree-ssa-live.c
Only in gcc/: tree-ssa-live.h
Only in gcc/: tree-ssa-loop-ch.c
Only in gcc/: tree-ssa-loop-im.c
Only in gcc/: tree-ssa-loop-ivcanon.c
Only in gcc/: tree-ssa-loop-ivopts.c
Only in gcc/: tree-ssa-loop-manip.c
Only in gcc/: tree-ssa-loop-niter.c
Only in gcc/: tree-ssa-loop-prefetch.c
Only in gcc/: tree-ssa-loop-unswitch.c
Only in gcc/: tree-ssa-loop.c
Only in gcc/: tree-ssa-math-opts.c
Only in gcc/: tree-ssa-operands.c
Only in gcc/: tree-ssa-operands.h
Only in gcc/: tree-ssa-phiopt.c
Only in gcc/: tree-ssa-phiprop.c
Only in gcc/: tree-ssa-pre.c
Only in gcc/: tree-ssa-propagate.c
Only in gcc/: tree-ssa-propagate.h
Only in gcc/: tree-ssa-reassoc.c
Only in gcc/: tree-ssa-sccvn.c
Only in gcc/: tree-ssa-sccvn.h
Only in gcc/: tree-ssa-sink.c
Only in gcc/: tree-ssa-strlen.c
Only in gcc/: tree-ssa-structalias.c
Only in gcc/: tree-ssa-tail-merge.c
Only in gcc/: tree-ssa-ter.c
Only in gcc/: tree-ssa-threadedge.c
Only in gcc/: tree-ssa-threadupdate.c
Only in gcc/: tree-ssa-uncprop.c
Only in gcc/: tree-ssa-uninit.c
Only in gcc/: tree-ssa.c
Only in gcc/: tree-ssanames.c
Only in gcc/: tree-stdarg.c
Only in gcc/: tree-stdarg.h
Only in gcc/: tree-streamer-in.c
Only in gcc/: tree-streamer-out.c
Only in gcc/: tree-streamer.c
Only in gcc/: tree-streamer.h
Only in gcc/: tree-switch-conversion.c
Only in gcc/: tree-tailcall.c
Only in gcc/: tree-vect-data-refs.c
Only in gcc/: tree-vect-generic.c
Only in gcc/: tree-vect-loop-manip.c
Only in gcc/: tree-vect-loop.c
Only in gcc/: tree-vect-patterns.c
Only in gcc/: tree-vect-slp.c
Only in gcc/: tree-vect-stmts.c
Only in gcc/: tree-vectorizer.c
Only in gcc/: tree-vectorizer.h
Only in gcc/: tree-vrp.c
Only in gcc/: tree.c
Only in gcc/: tree.def
Only in gcc/: tree.h
Only in gcc/: treestruct.def
Only in gcc/: tsystem.h
Only in gcc/: typeclass.h
Only in gcc/: value-prof.c
Only in gcc/: value-prof.h
Only in gcc/: var-tracking.c
Only in gcc/: varasm.c
Only in gcc/: varpool.c
Only in gcc/: vec.c
Only in gcc/: vec.h
Only in gcc/: vecir.h
Only in gcc/: vecprim.h
Only in gcc/: version.c
Only in gcc/: version.h
Only in gcc/: vmsdbg.h
Only in gcc/: vmsdbgout.c
Only in gcc/: web.c
Only in gcc/: xcoff.h
Only in gcc/: xcoffout.c
Only in gcc/: xcoffout.h

[-- Attachment #5: gcc.tgz --]
[-- Type: application/x-gzip, Size: 49874 bytes --]

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

* Re: [PATCH 1/2] gcc symbol database
  2012-08-06  5:37                           ` Yunfeng ZHANG
@ 2012-08-13  6:44                             ` Dodji Seketeli
  2012-09-06  1:34                               ` Yunfeng ZHANG
  0 siblings, 1 reply; 18+ messages in thread
From: Dodji Seketeli @ 2012-08-13  6:44 UTC (permalink / raw)
  To: Yunfeng ZHANG; +Cc: gcc-patches, Joseph S. Myers, Dave Korn, Tom Tromey

Hello Yunfeng,

Thank you for following up, and sorry for me reviewing your patches so
lately.  The libcpp changes are coming along nicely, IMHO.  I like the
fact that they are getting pretty minimal.  I just have a few mostly
cosmetic comments at this point.

[...]

> diff -cpr .pc/symdb_enhance_libcpp/libcpp/include/cpplib.h libcpp/include/cpplib.h
> *** .pc/symdb_enhance_libcpp/libcpp/include/cpplib.h	Wed Jul 25 10:57:16 2012
> --- libcpp/include/cpplib.h	Wed Jul 25 10:57:31 2012
> *************** struct cpp_callbacks
> *** 526,531 ****
> --- 526,548 ----
>        be expanded.  */
>     cpp_hashnode * (*macro_to_expand) (cpp_reader *, const cpp_token *);
>   
> +   /* The more powerful function extracts token than cpp_get_token. Later
> +    * callbacks show it. */
> +   void (*lex_token) (cpp_reader *, const cpp_token*);

For the sake of clarity, I'd change the signature and comment to
something more classically informative like (note that there should be
two spaces after between the '.' and the */):

    /* This callback is invoked when a token is lexed.  The RESULT
       parameter represents the lexed token.  */
    void (*lex_token) (cpp_reader *, const cpp_token *result);

> +   /* The pair is called when gcc expands macro. Enable lex_token in
> +    * macro_start_expand, you can catch all macro tokens. The pair can be called
> +    * nested, and the second parameter of macro_end_expand notifies you whether
> +    * macro is still expanding. */
> +   void (*macro_start_expand) (cpp_reader *, const cpp_token *,
> + 		                  const cpp_hashnode *);

Likewise, I'd change this into something like what comes below.  Also,
please try to use the same style as the rest of the comments of the
file; for instance, do not start each line of comment with a '*'; put
two spaces after each '.':

    /* This callback is invoked whenever a function-like macro
       represented by MACRO_NODE is about to be expanded.  MACRO_TOKEN
       is the token for the macro name and MACRO_NODE represents the
       macro.  */
    void (*macro_start_expand) (cpp_reader *, 
				const cpp_token *macro_token,
				const cpp_hashnode *macro_node);

> +   void (*macro_end_expand) (cpp_reader *, bool);

I believe that you don't need the last parameter, because this
callback should be called only when we know the macro *has* been
expanded.  So later down in _cpp_pop_context, I'd change:

*************** _cpp_pop_context (cpp_reader *pfile)
*** 2245,2250 ****
--- 2250,2257 ----
    /* decrease peak memory consumption by feeing the context.  */
    pfile->context->next = NULL;
    free (context);
+   if (pfile->cb.macro_end_expand)
+     pfile->cb.macro_end_expand (pfile, in_macro_expansion_p (pfile));
  }

into:

    if (in_macro_expansion_p (file) && pfile->cb.macro_end_expand)
      pfile->cb.macro_end_expand (pfile);

The callback that you actually set in your application, in so.c (in
gcc.tgz) would then change from:

    static void
    cb_macro_end (cpp_reader * pfile, bool in_expansion)
    {
      cpp_callbacks *cb = cpp_get_callbacks (pfile);
      if (!in_expansion)
	{
	  cache_end_let ();
	  mo_leave ();
	  cb->lex_token = NULL;
	      cb->macro_end_expand = NULL;
	}
    }

to:

    static void
    cb_macro_end (cpp_reader * pfile)
    {
      cpp_callbacks *cb = cpp_get_callbacks (pfile);
      cache_end_let ();
      mo_leave ();
      cb->lex_token = NULL;
      cb->macro_end_expand = NULL;
    }

And for the macro_end_expand, I'd add a comment and change the signature to:

    /* This callback is invoked whenever the macro previously notified by
       the macro_start_expand has been expanded.  */
    void (*macro_end_expand) (cpp_reader *);

> +   /* The pair is called when cpp directive (starting from `#', such as
> +    * `#define M', `#endif' etc) is encountered and reaches end. When enable
> +    * lex_token in start_directive, the sequence is lex_token("define"),
> +    * lex_token("M") ... */
> +   void (*start_directive) (cpp_reader *);

I'd change the comment to:

    /* This callback is invoked whenever a preprocessor directive (such as
       #define M) is encountered and about to be handled.  */

> +   void (*end_directive) (cpp_reader *);
> +

And I'd add a comment here that roughly reads:

    /* This callback is invoked when the directive previously notified
	by a call to the start_directive callback has been handled.
	Information about the directive is accessible at the field
	PFILE->directive.  */
    void (*end_directive) (cpp_reader *pfile);

[...]

>   static _cpp_buff *
>   funlike_invocation_p (cpp_reader *pfile, cpp_hashnode *node,
> ! 		      _cpp_buff **pragma_buff, unsigned *num_args)
>   {
>     const cpp_token *token, *padding = NULL;
>   
> --- 963,970 ----
>      returned buffer.  */
>   static _cpp_buff *
>   funlike_invocation_p (cpp_reader *pfile, cpp_hashnode *node,
> ! 		      _cpp_buff **pragma_buff, unsigned *num_args,
> ! 		      const cpp_token *head)
>   {

Please update the comment to say what the new parameter is.  I'd call
it macro_token, instead of head.

[...]

I have only lightly looked at the C front-end changes.  I'd like to
think about it more before sending comments, unless someone else beats
me to it.

Thanks.

-- 
		Dodji

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

* Re: [PATCH 1/2] gcc symbol database
  2012-08-13  6:44                             ` Dodji Seketeli
@ 2012-09-06  1:34                               ` Yunfeng ZHANG
  0 siblings, 0 replies; 18+ messages in thread
From: Yunfeng ZHANG @ 2012-09-06  1:34 UTC (permalink / raw)
  To: Dodji Seketeli; +Cc: gcc-patches, Joseph S. Myers, Dave Korn, Tom Tromey

What progress about my patch?

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

* [PATCH 1/2] gcc symbol database
@ 2012-05-28  8:41 Yunfeng ZHANG
  0 siblings, 0 replies; 18+ messages in thread
From: Yunfeng ZHANG @ 2012-05-28  8:41 UTC (permalink / raw)
  To: gcc-patches; +Cc: Dodji Seketeli, Joseph S. Myers, Dave Korn, Tom Tromey

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

Description (gccsymdb https://gccsymdb.googlecode.com/svn/trunk):
The patch I committed here is based on the idea -- collecting gcc internal
data (definition, file-dependence etc.) and outputting them into database for
further usage just like cscope. I've published the idea in previous mail loop
and sign a legal contact to gcc, last mail is
http://gcc.gnu.org/ml/gcc-patches/2010-06/msg00844.html. Now I want to
announce my new achievement to here, with later patches my plugin can collect
extern definitions and function call relationship to sqlite database, the
attachment is for 4.7.0, my site is for 4.6.2-4.6.3, see attachment/doc.txt
for start.  Later is some statistics: cscope database on 4.6.3 is about 130M,
my database is 23M, and my database is more accurate, without any macro/ifdef
intervention. I also hope gcc can accept my plugin as gcc standard plugin.
Later steps are try my plugins on gcc-4.7.0.
1) ./configure --prefix=/home/zyf/root/ --with-mpc=/home/zyf/root/
--with-gmp=/home/zyf/root/ --with-mpfr=/home/zyf/root/
2) cp -a /home/zyf/src/symdb.gcc/gcc.
patches/ patches
3) quilt push -a
4) make all-stage1
5) cd /home/zyf/src/symdb.gcc/ && make
6) cp gs init.sql helper.vim /home/zyf/src/gcc-4.7.0
7) cd /home/zyf/src/gcc-4.7.0
8) ./gs initdb ./
9) # Since my plugin only works on C not C++, but gcc uses stage1/g++ to
   # compile the whole stage2, so open Makefile and search `STAGE2_CXXFLAGS =
   # $(STAGE2_CFLAGS)', append `-xc' to the tail of the line.
   make STAGE2_CFLAGS="-fplugin=/home/zyf/src/symdb.gcc/symdb.so
   -fplugin-arg-symdb-dbfile=/home/zyf/src/gcc-4.7.0/gccsym.db" all-stage2
   # Ignore the error when linking cc1.
10) ./gs vacuumdb ./
11) vim
12) `:source helper.vim'
Using `CTRL-]' to search a definition.
Using `CTRL-[' to search which functions calls the function.
Using `CTRL-T' to jump back.
Using `Gs def yoursymbol' to search a definition.
Using `Gs callee yourfunction' to search function call relationship.

Testcases:
My plugin has a suite of testcases. Using bash+sqlite and test/run.sh to do
it.

ChangeLog includes mainly three files, libcpp/, gcc/ and gcc/c-family/. And
patch is sent as two blocks, one patch in libcpp/, another in gcc/.
ChangeLog
-------------------------
libcpp/
2012-05-24  Yunfeng ZHANG <zyf.zeroos@gmail.com>

      * include/cpplib.h (struct cpp_callbacks): Add new callbacks.
      macro_start_expand, macro_end_arg, macro_end_expand, start_directive,
      end_directive, directive_token.
      (cpp_token): Add file_offset field for every token.
      * internal.h (struct _cpp_line_note): Add adjust_offset field to adjust
      new cpp_token::file_offset.
      * directives.c (_cpp_handle_directive): Implement end_directive.
      * macro.c (enter_macro_context): Implement macro_end_arg.
      (cpp_get_token_1): Implement macro_start_expand and macro_end_expand.
      * lex.c (add_line_note): Add offset argument for file offset adjustment.
      (_cpp_clean_line): Using new add_line_note declaration.

gcc/
2012-05-24  Yunfeng ZHANG <zyf.zeroos@gmail.com>

     * plugin.def: New plugin events, one for broadcast new token is arrived,
     another is for new definition notification.
     * c-parser.c: Move c_id_kind/c_token definitions to c-family/c-common.h.
     (c_lex_one_token): Invoke PLUGIN_C_TOKEN callback.
     (c_parser_external_declaration): Invoke PLUGIN_EXTERN_DECL callback.
     (c_parser_declaration_or_fndef): Invoke PLUGIN_EXTERN_DECLSPECS,
     PLUGIN_EXTERN_VAR, PLUGIN_EXTERN_FUNC_OLD_PARAM, PLUGIN_EXTERN_FUNC
     callbacks.
     (c_parser_enum_specifier): Invoke PLUGIN_ENUM_SPECIFIER callback.
     (c_parser_postfix_expression_after_primary): Invoke PLUGIN_CALL_FUNCTION
     callback.
     * plugin.c (register_callback): Handle new plugin events.
     (invoke_plugin_callbacks_full): Likewise.
     * doc/plugins.texi: Document new plugin events.

gcc/c-family/
2012-05-24  Yunfeng ZHANG <zyf.zeroos@gmail.com>
     * c-lex.c: Include plugin.h.
     (c_lex_with_flags): Invoke PLUGIN_CPP_TOKEN callback.
     * c-common.h: Include c-pragma.h. Move c_id_kind/c_token definitions from
     c-parser.c.

Patch 1 of 2 on libcpp/
--------------------------------
diff -upr .pc/symdb_enhance_libcpp/libcpp/directives.c libcpp/directives.c
--- .pc/symdb_enhance_libcpp/libcpp/directives.c    2011-10-17
17:59:12.000000000 +0800
+++ libcpp/directives.c    2012-05-25 14:56:56.751134781 +0800
@@ -492,6 +492,8 @@ _cpp_handle_directive (cpp_reader *pfile
   else if (skip == 0)
     _cpp_backup_tokens (pfile, 1);

+  if (pfile->cb.end_directive)
+    pfile->cb.end_directive (pfile);
   end_directive (pfile, skip);
   if (was_parsing_args && !pfile->state.in_deferred_pragma)
     {
diff -upr .pc/symdb_enhance_libcpp/libcpp/include/cpplib.h
libcpp/include/cpplib.h
--- .pc/symdb_enhance_libcpp/libcpp/include/cpplib.h    2011-12-21
04:44:13.000000000 +0800
+++ libcpp/include/cpplib.h    2012-05-25 14:56:56.745507332 +0800
@@ -218,10 +218,10 @@ struct GTY(()) cpp_identifier {
        node;
 };

-/* A preprocessing token.  This has been carefully packed and should
-   occupy 16 bytes on 32-bit hosts and 24 bytes on 64-bit hosts.  */
+/* A preprocessing token. */
 struct GTY(()) cpp_token {
   source_location src_loc;    /* Location of first char of token.  */
+  int file_offset;
   ENUM_BITFIELD(cpp_ttype) type : CHAR_BIT;  /* token type */
   unsigned short flags;        /* flags - see above */

@@ -522,6 +522,24 @@ struct cpp_callbacks
      be expanded.  */
   cpp_hashnode * (*macro_to_expand) (cpp_reader *, const cpp_token *);

+  /* macro_{start/end}_expand are called when gcc starts to expand macro, note
+   * if A macro includes B macro, the pair is called multiple times. */
+  void (*macro_start_expand) (cpp_reader *, const cpp_token *,
+          const cpp_hashnode *);
+  void (*macro_end_expand) (cpp_reader *);
+  /* Called when a function-like macro stops collecting macro parameters,
+   * cancel = true, macro expansion is canceled. */
+  void (*macro_end_arg) (cpp_reader *, bool cancel);
+  /* The pair is called when cpp directive (starting from `#', such as
+   * `#define', `#endif' etc) is encountered and reaches end. */
+  void (*start_directive) (cpp_reader *, const cpp_token*);
+  void (*end_directive) (cpp_reader *);
+  /* The more powerful function getting token than cpp_get_token. Here, name
+   * directive_token maybe makes you confused, it's named from
+   * libcpp/lex.c:_cpp_lex_direct, there isn't relationship between
+   * directive_token and {start, end}_directive above. */
+  void (*directive_token) (cpp_reader *, const cpp_token*);
+
   /* Called to emit a diagnostic.  This callback receives the
      translated message.  */
   bool (*error) (cpp_reader *, int, int, source_location, unsigned int,
diff -upr .pc/symdb_enhance_libcpp/libcpp/internal.h libcpp/internal.h
--- .pc/symdb_enhance_libcpp/libcpp/internal.h    2012-01-09
16:48:43.000000000 +0800
+++ libcpp/internal.h    2012-05-25 14:56:56.752132995 +0800
@@ -291,6 +291,11 @@ struct _cpp_line_note
      intervening space, 0 represents a note that has already been handled,
      and anything else is invalid.  */
   unsigned int type;
+
+  /* file offset adjustment is recorded by add_line_note to adjust
+   * cpp_token::file_offset. The case is when some spaces are left after an
+   * escaped newline `\', cpp_token::file_offset becomes inexact. */
+  const unsigned char *adjust_offset;
 };

 /* Represents the contents of a file cpplib has read in.  */
diff -upr .pc/symdb_enhance_libcpp/libcpp/lex.c libcpp/lex.c
--- .pc/symdb_enhance_libcpp/libcpp/lex.c    2011-12-08 06:05:59.000000000 +0800
+++ libcpp/lex.c    2012-05-25 14:56:56.747508973 +0800
@@ -51,7 +51,8 @@ static const struct token_spelling token
 #define TOKEN_SPELL(token) (token_spellings[(token)->type].category)
 #define TOKEN_NAME(token) (token_spellings[(token)->type].name)

-static void add_line_note (cpp_buffer *, const uchar *, unsigned int);
+static void add_line_note (cpp_buffer *, const uchar *, unsigned int,
+               const uchar *);
 static int skip_line_comment (cpp_reader *);
 static void skip_whitespace (cpp_reader *, cppchar_t);
 static void lex_string (cpp_reader *, cpp_token *, const uchar *);
@@ -82,7 +83,8 @@ cpp_ideq (const cpp_token *token, const
 /* Record a note TYPE at byte POS into the current cleaned logical
    line.  */
 static void
-add_line_note (cpp_buffer *buffer, const uchar *pos, unsigned int type)
+add_line_note (cpp_buffer *buffer, const uchar *pos, unsigned int type,
+           const uchar * offset)
 {
   if (buffer->notes_used == buffer->notes_cap)
     {
@@ -93,6 +95,7 @@ add_line_note (cpp_buffer *buffer, const

   buffer->notes[buffer->notes_used].pos = pos;
   buffer->notes[buffer->notes_used].type = type;
+  buffer->notes[buffer->notes_used].adjust_offset = offset;
   buffer->notes_used++;
 }

@@ -689,7 +692,7 @@ _cpp_clean_line (cpp_reader *pfile)
         {
           /* Have a trigraph.  We may or may not have to convert
              it.  Add a line note regardless, for -Wtrigraphs.  */
-          add_line_note (buffer, s, s[2]);
+          add_line_note (buffer, s, s[2], 0);
           if (CPP_OPTION (pfile, trigraphs))
             {
               /* We do, and that means we have to switch to the
@@ -734,7 +737,7 @@ _cpp_clean_line (cpp_reader *pfile)

       /* Have an escaped newline; process it and proceed to
      the slow path.  */
-      add_line_note (buffer, p - 1, p != d ? ' ' : '\\');
+      add_line_note (buffer, p - 1, p != d ? ' ' : '\\', s + 1);
       d = p - 2;
       buffer->next_line = p - 1;

@@ -759,14 +762,14 @@ _cpp_clean_line (cpp_reader *pfile)
           if (p == buffer->next_line || p[-1] != '\\')
         break;

-          add_line_note (buffer, p - 1, p != d ? ' ': '\\');
+          add_line_note (buffer, p - 1, p != d ? ' ': '\\', s + 1);
           d = p - 2;
           buffer->next_line = p - 1;
         }
       else if (c == '?' && s[1] == '?' && _cpp_trigraph_map[s[2]])
         {
           /* Add a note regardless, for the benefit of -Wtrigraphs.  */
-          add_line_note (buffer, d, s[2]);
+          add_line_note (buffer, d, s[2], 0);
           if (CPP_OPTION (pfile, trigraphs))
         {
           *d = _cpp_trigraph_map[s[2]];
@@ -789,7 +792,7 @@ _cpp_clean_line (cpp_reader *pfile)
  done:
   *d = '\n';
   /* A sentinel note that should never be processed.  */
-  add_line_note (buffer, d + 1, '\n');
+  add_line_note (buffer, d + 1, '\n', s + 1);
   buffer->next_line = s + 1;
 }

@@ -1886,6 +1889,8 @@ _cpp_lex_token (cpp_reader *pfile)
          handles the directive as normal.  */
           && pfile->state.parsing_args != 1)
         {
+          if (pfile->cb.start_directive)
+        pfile->cb.start_directive (pfile, result);
           if (_cpp_handle_directive (pfile, result->flags & PREV_WHITE))
         {
           if (pfile->directive_result.type == CPP_PADDING)
@@ -2032,6 +2037,17 @@ _cpp_lex_direct (cpp_reader *pfile)
       _cpp_process_line_notes (pfile, false);
       result->src_loc = pfile->line_table->highest_line;
     }
+  if (buffer->cur_note != 0)
+    {
+      int index = buffer->cur_note - 1;
+      result->file_offset = buffer->cur - buffer->buf;
+      result->file_offset +=
+    buffer->notes[index].adjust_offset - buffer->notes[index].pos;
+    }
+  else
+    {
+      result->file_offset = buffer->cur - buffer->buf;
+    }
   c = *buffer->cur++;

   if (pfile->forced_token_location_p)
@@ -2346,6 +2362,8 @@ _cpp_lex_direct (cpp_reader *pfile)
       break;
     }

+  if (pfile->cb.directive_token)
+    pfile->cb.directive_token (pfile, result);
   return result;
 }

diff -upr .pc/symdb_enhance_libcpp/libcpp/macro.c libcpp/macro.c
--- .pc/symdb_enhance_libcpp/libcpp/macro.c    2012-01-09
22:15:25.000000000 +0800
+++ libcpp/macro.c    2012-05-25 14:56:56.749508416 +0800
@@ -1029,9 +1029,13 @@ enter_macro_context (cpp_reader *pfile,
           if (pragma_buff)
         _cpp_release_buff (pfile, pragma_buff);

+          if (pfile->cb.macro_end_arg)
+        pfile->cb.macro_end_arg (pfile, true);
           return 0;
         }

+      if (pfile->cb.macro_end_arg)
+        pfile->cb.macro_end_arg (pfile, false);
       if (macro->paramc > 0)
         replace_args (pfile, node, macro,
               (macro_arg *) buff->base,
@@ -2263,6 +2267,8 @@ cpp_get_token_1 (cpp_reader *pfile, sour
       if (pfile->context->c.macro)
         ++num_expanded_macros_counter;
       _cpp_pop_context (pfile);
+      if (pfile->cb.macro_end_expand)
+        pfile->cb.macro_end_expand (pfile);
       if (pfile->state.in_directive)
         continue;
       result = &pfile->avoid_paste;
@@ -2321,8 +2327,14 @@ cpp_get_token_1 (cpp_reader *pfile, sour
         }
         }
       else
-        ret = enter_macro_context (pfile, node, result,
-                       virt_loc);
+          {
+           if (pfile->cb.macro_start_expand)
+         pfile->cb.macro_start_expand (pfile, result, node);
+       ret = enter_macro_context (pfile, node, result, virt_loc);
+     if (ret == 0 && pfile->cb.macro_end_expand)
+       /* macro expansion is canceled. */
+       pfile->cb.macro_end_expand (pfile);
+         }
       if (ret)
          {
           if (pfile->state.in_directive || ret == 2)

[-- Attachment #2: mail.tgz --]
[-- Type: application/x-gzip, Size: 59726 bytes --]

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

end of thread, other threads:[~2012-09-06  1:34 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CA+dUcj3G+MhuQSOQVo5H=wK7R8PQ0MSOdX_s0+xM_ZvXXJkCJQ@mail.gmail.com>
2012-06-04 14:02 ` [PATCH 1/2] gcc symbol database Dodji Seketeli
2012-06-05  6:56   ` Yunfeng ZHANG
2012-06-21  7:48     ` Yunfeng ZHANG
2012-06-27  8:46       ` Yunfeng ZHANG
2012-07-13 19:32       ` Dodji Seketeli
2012-07-16 10:09         ` Yunfeng ZHANG
2012-07-16 15:31           ` Dodji Seketeli
2012-07-17  7:14             ` Yunfeng ZHANG
2012-07-17  9:06               ` Dodji Seketeli
2012-07-18  2:11                 ` Yunfeng ZHANG
2012-07-18  8:04                   ` Dodji Seketeli
2012-07-19  1:18                     ` Yunfeng ZHANG
2012-07-19  7:04                       ` Yunfeng ZHANG
2012-07-19  8:06                         ` Dodji Seketeli
2012-08-06  5:37                           ` Yunfeng ZHANG
2012-08-13  6:44                             ` Dodji Seketeli
2012-09-06  1:34                               ` Yunfeng ZHANG
2012-05-28  8:41 Yunfeng ZHANG

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