11

I was fascinated by the "press Tab to search site" feature in chromium, so naturally I wanted to see how exactly it was implemented in code.

A little background for anybody who aren't familiar with this. After navigating to some site, say wikipedia, and doing a search, chromium remembers the name of the query variable and will let you press tab and search the site directly from the address bar. Neat!

Problem is the codebase for chromium is huge and I've had no luck in finding the method/function that handles this.

How do you approach a large codebase when you are looking for the implementation of a particular piece of functionality? Any tricks for narrowing it down? Preferably it should not require building the software with debug symbols and following the flow through the program.

hanDerPeder
  • 397
  • 2
  • 12
  • Regarding your specific problem, Google Chrome is Apple's WebKit browser engine plus a lot of Googlisms. Having worked inside WebKit, I suspect you'll find this feature's implementation is scattered among quite a few different source files, maybe in widely separated source directories. – Bob Murphy Dec 14 '10 at 03:25

3 Answers3

10

There is no one size fits all approach to this sort of problem. But for this one I would try these:

  • If there are any unique messages associated with the operation, grep all the source files for that string. A common pitfall of this technique is that messages might be assembled from pieces within the application, so it is often helpful to grep for a unique short phrase—or even a single word—to identify the source of the message. Once the text is found, then finding what references it often requires more text searches.

  • Trace execution from an easy-to-find point, like the command processing and dispatch loop. I'd look for a Tab key case and follow where it leads.

  • Look at source code directory and filenames for hints. Software is often constructed rationally, with good engineers dividing and conquering in a sensible way.

wallyk
  • 56,922
  • 16
  • 83
  • 148
  • +1 An editor with a fast recursive search capability is your friend here. I often use one to fish for words I think are likely to be connected with the feature I want, and then if I get what looks like a related routine, I start seeing what it calls and what calls it. – Bob Murphy Dec 14 '10 at 03:22
  • When the code base gets big (millions of lines), "recursive search" and "grep" stop being helpful;they take too long and they produce too many false positive hits. Then you need a language-sensitive code search engine that indexes the code base to accellerate the searches and minimize false hits. Our search engine handles big, mixed code bases well: http://www.semanticdesigns.com/Products/SearchEngine – Ira Baxter Dec 15 '10 at 01:18
6

A test coverage tool is a good way to do this. They tell you what part of an application is exercised by a test.

Instrument the application to collect test coverage. Execute the functionality you care about. Record what is executed. Execute something similar, but not the same as the functionality you want. Record this. Take the set difference over the coverage. The diff selects code involved in the functionality of interest, excluding code which is common to similar functionality.

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
  • Excellent idea! (Naturally it had 0 votes.) – j_random_hacker Dec 14 '10 at 04:18
  • This sounds interesting. Never used a test coverage tool before. Any recommendations for C/C++? gcov seems like an obvious candidate. – hanDerPeder Dec 14 '10 at 05:25
  • gcov can collect the coverage data, but AFAIK it is awkward to compute the test coverage difference. My company also offers test coverage tools for many languages, including C, C++, C#, Java, .... These tools provide the ability to capture both test coverage vectors and compute the set difference directly and easily. See http://www.semanticdesigns.com/Products/TestCoverage – Ira Baxter Dec 14 '10 at 06:52
0

Ask the Chromium team. They don't give points or bronze pixels but they're definitely the authority and right people to ask this sort of questions.

wilhelmtell
  • 57,473
  • 20
  • 96
  • 131
  • 2
    This is not a helpful answer. The question is about approaches in general. – Zoodle Von Noodleson Dec 14 '10 at 03:25
  • Not it's not. It's very specific. – wilhelmtell Dec 14 '10 at 03:35
  • 1
    @Wilhelm No, it's a very general question. The chromium thing was just given as an example. – Maxpm Dec 14 '10 at 03:39
  • 1
    @Maxpm well then, my answer was also given as an example. – wilhelmtell Dec 14 '10 at 03:42
  • 2
    Don't get me wrong here. If you have one community that can give you proper, correct and authoritative answer to your narrow question, and then you have another community than can give you a speculative, opinionated answer to that same question -- the choice of who to ask is easy. StackOverflow is fun, but seriously now. If you're here to talk I'm cool, but if you're here to get a specific answer to a specific question then the Chromium people are your men. – wilhelmtell Dec 14 '10 at 03:49
  • @wilhelmtell, the question was about approaches in general. I provided the chromium example to give context. I'm sorry if I failed to make that clear. Perhaps I went a little overboard with the tagging. – hanDerPeder Dec 14 '10 at 05:17