Thread: Analyze code in large systems

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    5

    Cool Analyze code in large systems

    Hello. I am working on a large system written in C programming. I am not fully aware of the whole system. I get an error and I found which function is causing that error. Any ideas how I could find the code of that function?
    In general, how to you usually "walk around" large systems and read the code easily?

    Any ideas (grep maybe) using Linux/Unix systems are preferred

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    ctags? http://linux.die.net/man/1/ctags - emacs allows you to load a tags file and use it to find symbols.

    Otherwise, "grep -r symbolname ." in the root of the source tree works quite well - unless of course some "clever" use of macros (in which case ctags will probably also fail).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Why bbebfe is not bbebfe? bbebfe's Avatar
    Join Date
    Nov 2008
    Location
    Earth
    Posts
    27
    vim+tags may be a choice.

  4. #4
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    I'm sure someone else in your organisation must have tried to find some code before. How do they do it? It's not usually a good idea to reinvent the wheel.

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  5. #5
    Registered User
    Join Date
    Nov 2008
    Posts
    5

    Cool

    After searching for a while here are the methods I found for reading/analyzing source code:

    • Using an editor: Most text editors support regular expressions. Here is a guide for regular expressions in vim and a guide for regular expressions in emacs.
    • Using the ctags tool: matsp already mention that in previous post.
    • Code Searching with grep: Useful when working with large systems with many directories and files.

      Example 1:
      Code:
      grep -n -r  '^test' *
      will show the file and the line containing the definition for the function test.

      Example 2:
      Code:
      grep -n -r  'test' *
      will show both the definition and all uses.


      Example 3: The Linux Kernel Load Calculation
    • Tools:

      The cscope tool: A vim tutorial.

      sourcenav tool





    Please feel free to comment or suggest any more methods.

    I know that some people might be aware of all these, but it might be useful for some beginners (like me for example).

  6. #6
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    If interested a good link to help address researching and analyzing a large database of source code and repositories is below

    http://lxr.linux.no/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing Code
    By ILoveVectors in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2005, 12:27 AM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. Can someone help me understand this example program
    By Guti14 in forum C Programming
    Replies: 6
    Last Post: 09-06-2004, 12:19 PM
  4. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM

Tags for this Thread