Re: need to find functions definitions
On Tuesday 21 October 2008 20:07:10 `VL wrote: > Hello, ALL. > > I recently started to actively program using C and found that tools like > ctags or cscope do not work properly for big projects. Quite ofthen they > can't find function or symbol definition. The problem here is that they > don't use full code parsing, but just some sort of regular expressions. > > I need a tool for automatic code exploration that can at least find > definition for every symbol without problems. If you know any - please > tell. > > Now, to gcc. It seems to me that existing and working compiler is an ideal > place to embedd such tool - since it already knows all the things required. > > I have one idea: i'm almost sure that inside gcc somewhere there is a place > (function i beleive) that is called each time during compilation when > definition of something (type, variable,function...) found and in this > place gcc has context information - source file and line where this > definition came from. So if i add something like printf("DEFINITION: > %s,%s,%d\n", info->object_type,info->src_file,info->line) into that place, > i will get information about every thing that compiler found. > > What i like more about this way of getting information about symbol > definition is that i get the only reference to that part of source that was > actually compiled. I.e. if there are a lot of #ifdef's, it's is hard to > know what part of code will be used. > > So, my questions is: > > 1) Is it possible ? Is there a single place where all information is easily > accessible ? 2) If yes - where is it and where can i find details about > internals of gcc? 3) Any good alternatives for cscope/ctags? It seemed to > me that > eclipse has some good framework, but it looks to be too much integrated > with it... > > Thank you! Hi, wouldn't it be easier to just compile with debug symbols (-g) and then look into the symbol table or into the DWARF debug information? Both can be done with the tool objdump contained in the binutils (normally installed on each linux), and there are libraries for both tasks to read and use the information in own applications. You'll get symbol (functions/methods, arguments, variables) names, addresses, types, etc. Tim
Re: need to find functions definitions
`VL wrote: > Hello, ALL. > > I recently started to actively program using C and found that tools like > ctags or cscope do not work properly for big projects. Quite ofthen they > can't find function or symbol definition. The problem here is that they don't > use full code parsing, but just some sort of regular expressions. > > I need a tool for automatic code exploration that can at least find definition > for every symbol without problems. If you know any - please tell. > > Now, to gcc. It seems to me that existing and working compiler is an ideal > place to embedd such tool - since it already knows all the things required. > > I have one idea: i'm almost sure that inside gcc somewhere there is a place > (function > i beleive) that is called each time during compilation when definition of > something (type, variable,function...) > found and in this place gcc has context information - source file and line > where this definition came from. > So if i add something like printf("DEFINITION: %s,%s,%d\n", > info->object_type,info->src_file,info->line) into > that place, i will get information about every thing that compiler found. > > What i like more about this way of getting information about symbol > definition is that > i get the only reference to that part of source that was actually compiled. > I.e. if there are > a lot of #ifdef's, it's is hard to know what part of code will be used. > > So, my questions is: > > 1) Is it possible ? Is there a single place where all information is easily > accessible ? > 2) If yes - where is it and where can i find details about internals of gcc? > 3) Any good alternatives for cscope/ctags? It seemed to me that > eclipse has some good framework, but it looks to be too much integrated with > it... All the information you need is in the debuginfo that is embedded in the object files. Existing binutils can read this info -- all you have to do is import it. Andrew.
How to extend lanuage C in GCC ?
I'm porting for a microcontroller. And now I want to add some features to the current language C int GCC (for example some directives such as near, far , ). SO could you please tell me how I can do that ? Thank you very much.
Re: How to extend lanuage C in GCC ?
2008/10/22 Dong Phuong <[EMAIL PROTECTED]>: > > I'm porting for a microcontroller. And now I want to > add some features to the current language C int GCC > (for example some directives such as near, far , > ). SO could you please tell me how I can do that > ? Hi, I am not sure if it is solves all your cases, but things like far, near, that are usually handled as attributes. Please take a look at http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Function-Attributes.html#Function-Attributes. Cheers, Piotr
Re: How to extend lanuage C in GCC ?
Yes, things like near, far, .. are all that I need. I think this is the right way for me. I've glanced at the link you gave me. I see that the M32R/D has the attribute "model" with value "small, medium and target", I don't know whether this is the standard atributes for all targets in GCC that I can use or I have to do something to add my own attribute. And if I want to add more value , for example "xlarge...", what do I have to do ? Thank you very much. --- Piotr Rak <[EMAIL PROTECTED]> wrote: > Hi, > I am not sure if it is solves all your cases, but > things like far, > near, that are usually handled as attributes. > Please take a look at > http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Function-Attributes.html#Function-Attributes. > > Cheers, > Piotr >
conditional assigments vs. "may be used uninitialized"
Info node (gcc)Warning Options mentions that gcc warns about int save_y; if (change_y) save_y = y, y = new_y; ... if (change_y) y = save_y; However that's not always true, so it looks like gcc does have the smarts to drop the warning. Could that be improved? gcc -W -O does not warn about this snippet, but it does warn with -DMACRO or -O2. So it looks like the information that this code is safe is available but not used. #define foo(x) (x < 3 ? 0 : x) #ifndef MACRO int (foo)(int x) { return foo(x); } #undef foo #endif int bar(int y, const int change_y) { int save_y; if (change_y) save_y = y, y = -y; y = foo(y); if (change_y) y = save_y; return y; } gcc 4.3.2 on x86_64-unknown-linux-gnu. -- Hallvard
Re: conditional assigments vs. "may be used uninitialized"
On Wed, Oct 22, 2008 at 12:57 PM, Hallvard B Furuseth <[EMAIL PROTECTED]> wrote: > Info node (gcc)Warning Options mentions that gcc warns about > >int save_y; >if (change_y) save_y = y, y = new_y; >... >if (change_y) y = save_y; > > However that's not always true, so it looks like gcc does have > the smarts to drop the warning. Could that be improved? > > gcc -W -O does not warn about this snippet, but it does warn with > -DMACRO or -O2. So it looks like the information that this code > is safe is available but not used. Well the reason it is not warning in the -UMACRO case is because jump threading optimization has happened and removes one of the if(change_y) condition. Thanks, Andrew Pinski
Re: conditional assigments vs. "may be used uninitialized"
2008/10/22 Hallvard B Furuseth <[EMAIL PROTECTED]>: > Info node (gcc)Warning Options mentions that gcc warns about > >int save_y; >if (change_y) save_y = y, y = new_y; >... >if (change_y) y = save_y; > > However that's not always true, so it looks like gcc does have > the smarts to drop the warning. Could that be improved? In the case of Wuninitialized warnings, if GCC gets the answer right, it may not get the answer by the same reasoning as you. A notable example is the following code: 1 sub() 2 { 3 int i = 0; 4 int j = 0; 5 int k; 6 7 while ((i | j) == 0) 8 { 9 k = 10; 10 i = sub (); 11 } 12 13 return k; 14 } Here GCC does not warn for line 13. But GCC never knows that the loop is executed at least once. In fact what happens is that GCC assumes that the uninitialized value of k is 10 and hence it propagates this value so line 13 becomes return 10. If you substitute 0 by a variable in line 7 there is still no warning. If you are interested in improving uninitialized warnings I would suggest to take a look to http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings (It is perhaps a bit outdated, since a few things have improved in GCC 4.4). Cheers, Manuel.
Re: thread build on solaris
thanks.. mea culpa, I assumed that 'testing fixes' solely meant making the fixincludes ready for release.. Ed On Tue, Oct 21, 2008 at 9:49 PM, Eric Botcazou <[EMAIL PROTECTED]> wrote: >> Yes, I got that from the README. What I was looking for was a >> *shortcut*, > > "5. Testing fixes" precisely documents a shortcut. > > -- > Eric Botcazou >
gcc-4.2-20081022 is now available
Snapshot gcc-4.2-20081022 is now available on ftp://gcc.gnu.org/pub/gcc/snapshots/4.2-20081022/ and on various mirrors, see http://gcc.gnu.org/mirrors.html for details. This snapshot has been generated from the GCC 4.2 SVN branch with the following options: svn://gcc.gnu.org/svn/gcc/branches/gcc-4_2-branch revision 141310 You'll find: gcc-4.2-20081022.tar.bz2 Complete GCC (includes all of below) gcc-core-4.2-20081022.tar.bz2 C front end and core compiler gcc-ada-4.2-20081022.tar.bz2 Ada front end and runtime gcc-fortran-4.2-20081022.tar.bz2 Fortran front end and runtime gcc-g++-4.2-20081022.tar.bz2 C++ front end and runtime gcc-java-4.2-20081022.tar.bz2 Java front end and runtime gcc-objc-4.2-20081022.tar.bz2 Objective-C front end and runtime gcc-testsuite-4.2-20081022.tar.bz2The GCC testsuite Diffs from 4.2-20081015 are available in the diffs/ subdirectory. When a particular snapshot is ready for public consumption the LATEST-4.2 link is updated and a message is sent to the gcc list. Please do not use a snapshot before it has been announced that way.
Re: Fwd: conditional assigments vs. "may be used uninitialized"
Seongbae Park ??? ??? wrote: David, Just in case you haven't noticed this thread - I figured you may want to comment on it. Seongbae -- Forwarded message -- From: Manuel López-Ibáñez <[EMAIL PROTECTED]> Date: Wed, Oct 22, 2008 at 2:00 PM Subject: Re: conditional assigments vs. "may be used uninitialized" To: Hallvard B Furuseth <[EMAIL PROTECTED]> Cc: gcc@gcc.gnu.org 2008/10/22 Hallvard B Furuseth <[EMAIL PROTECTED]>: Info node (gcc)Warning Options mentions that gcc warns about int save_y; if (change_y) save_y = y, y = new_y; ... if (change_y) y = save_y; However that's not always true, so it looks like gcc does have the smarts to drop the warning. Could that be improved? Currently gcc relies on jump threading to get this right (path sensitivity). I have a patch that does predicate aware uninitialized variable analysis which does not rely on any such transformations. It covers the following cases (simple example shown): Example 1: flag = 0; if (some_condition) { v = flag = 1; } if (flag) { use (v); } This case usually results from inline transformation as in: if (init_var(&v) == false) return; use (v); Example 2: if (cond1) v = ... ... if (cond2) use (v); if cond1 is a superset of cond2, no warning is given. For instance: if (x > 0 || y > 0) v = ... ... if (x > 10) if ( m < 0) use (v); The patch is pretty big, so I am waiting for stage1 is reopened to submit. Thanks, David In the case of Wuninitialized warnings, if GCC gets the answer right, it may not get the answer by the same reasoning as you. A notable example is the following code: 1 sub() 2 { 3 int i = 0; 4 int j = 0; 5 int k; 6 7 while ((i | j) == 0) 8 { 9 k = 10; 10 i = sub (); 11 } 12 13 return k; 14 } Here GCC does not warn for line 13. But GCC never knows that the loop is executed at least once. In fact what happens is that GCC assumes that the uninitialized value of k is 10 and hence it propagates this value so line 13 becomes return 10. If you substitute 0 by a variable in line 7 there is still no warning. If you are interested in improving uninitialized warnings I would suggest to take a look to http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings (It is perhaps a bit outdated, since a few things have improved in GCC 4.4). Cheers, Manuel.
Re: How to extend lanuage C in GCC ?
Your information is very helpful to me. Thanh you very much. --- Piotr Rak <[EMAIL PROTECTED]> wrote: > Some of them are common, other are target specific. > To add new attribute, you might want take a look at > c_common_attribute_table in gcc/c-common.c, > attribute_spec struct in > gcc/tree.h, and 'grep attribute_spec gcc/config/*'. > Hope that helps. > > Cheers, > Piotr >
Where in GCC that allocates the memory for variables ??
I'm porting for a microcontroller with segmented memory. And I want to see how memory are allocated for variables with different directives such as NEAR, FAR . So where can I find it in GCC source code ?
Re: Where in GCC that allocates the memory for variables ??
memory allocation are three types: a. stack allocation. b. dynamic heap-based - using api like malloc()and this happened in the heap areadepending on ELF loading and architecture-specific. c. static memory - this is purely embedded inside the ELF file, so during loading it just got mapped into memory. No allocation is needed, but it will follow the ELF file-format. Eg, if u create several sections inside the ELF file, each of these section will get a page for itself in the loaded memory. On Thu, Oct 23, 2008 at 8:41 AM, Dong Phuong <[EMAIL PROTECTED]> wrote: > > I'm porting for a microcontroller with segmented > memory. And I want to see how memory are allocated for > variables with different directives such as NEAR, FAR > . So where can I find it in GCC source code ? > > > > -- Regards, Peter Teoh