The Query System
The most important task of &kapp; is to execute Cscope queries and display their results. Queries are always performed on the cross-reference database of the active project.
&kapp; currently supports the following query types:
Find all references to a symbolFind a symbol's global definitionFind all functions called by a given functionFind all functions calling a given functionFind a text stringFind an EGrep pattern (regular expression)Find a file's path by its nameFind all files including a given fileDisplay a call-tree for a given function
A symbol, as referred to in the above list, may be a function, a global variable, a structure, a union or a type definition.
The cross-reference database may become obsolete when source files are modified, resulting in inaccurate (or simply wrong) query results. &kapp; has two ways for refreshing the database, manual and automatic. Manual database rebuilds are available through the CscopeRebuild Database menu command. Selecting this command will instruct Cscope to immediately rebuild the cross-reference database.
Automatic database rebuilds are enabled per-project, an option controlled by the Project Properties dialogue. Since a database rebuild may be a time and resource-consuming operation, &kapp; does not invoke this procedure after every change to the source code. Instead, changes to the code initiate a timer (whose value is determined by the user in the Project Properties dialogue). Once this timer elapses, &kapp; instructs Cscope to rebuild the database. Code modifications that occur while the timer is running reset its value.
A project's database is also updated whenever that project is opened.
Running a Query
A query can be started in one of three ways:
The main menuKeyboard shortcutsThe editor's context-menu
To start a query from the main menu, select the desired query type from the Cscope menu. This will display a dialogue box prompting you for the query's text. The text to enter depends upon the query's type.
The query dialogueThe query dialogueTypeThe type of query to perform. This value defaults to the requested type, by can be changed by selecting a different entry in the list.SymbolEnter the symbol to query in this box. The default value is the symbol currently under the editor's cursor (if any).Search for a Sub-StringMark this check-box to treat the entered text as part of a symbol (will query all symbols containing the entered text as a sub-string).OKRuns the query.HintProvides a list of possible matches to the entered symbol.CancelCloses the dialogue without running the query.Suggested SymbolsA list of known symbols matching the text in the symbol box.Hint OptionsThese buttons affect the way text in the symbol box is matched to fill the suggested symbols list.Symbols Beginning With...Choose this option to match symbols starting with the given text.Symbols Containing...Choose this option to match symbols containing the given text.
Any text selected in the editor when a query is requested will be automatically copied to the query dialogue. If no text is selected, KScope attempts to guess the requested symbol from the current location of the cursor.
Each menu item is associated with a keyboard shortcut. These shortcuts follow the convention of using the Ctrl key, together with the numeric query index used by Cscope (this should allow experienced Cscope users to get quickly acquainted with &kapp;). For example, use Ctrl1 to look-up a symbol's definition. The call-tree is an exception to this convention (as it is not a native Cscope query). See the Command Reference for a complete listing of all menu and shortcut options.
The EGrep query is invoked using Ctrl5, as Ctrl6 is already used by &kate;.
The third way of starting a query is by right-clicking inside an editor window. This invokes the context-menu, that displays the same options as in the Cscope section of the main menu. Using a context-menu is easy when combined with a symbol selection in the editor: position the text cursor inside a symbol, and then right click to display the context-menu.
A query may take some time to complete, depending on its type and the size of the project. &kapp; displays a progress indicator during long queries. If Cscope's command line option is used, this progress indication is accurate, and displays the percentage of files already searched in. In case this option was omitted (e.g., if working with a version of Cscope prior to 15.5), &kapp; will present a dummy progress bar, used simply to indicate that a query is running, and that &kapp; has not frozen. Please refer to the section Configuring &kapp; for more information.
The Query Results Window
When a query has terminated, its output is displayed in the query window, at the bottom of &kapp;'s main window. This window can manage several result pages simultaneously, with each page holding the results of a different query. Each page is associated with a tab that displays a summary of the query that generated these results. This tab is used to bring the results page forward, and is also associated with several page operations through a close button and a context menu.
By default, query results are displayed in the currently active page, overriding any prior contents. To keep a results page unchanged, the page needs to be "locked". Locked query pages are never overridden. The contents of these pages are also saved when the project is closed, and are restored when the project is reopened. To lock a project, either click the Lock/Unlock Query toggle button to the right of the query window, or use the context menu (available by right-clicking the page's tab.) The same methods can also be used to unlock a query.
New query pages can also be created explicitly, by using either the New Query button to the right of the query window, or the context menu available by right-clicking the tab area of the query window.
Each entry in a query results page represents a symbol or text string that complies to the search criteria. The entry is composed of four sections:
The path of the file in which the symbol or string were foundThe name of the function containing the symbol or text stringThe line number in this fileThe text of this line
By default, results are sorted according to the file name. This can be changed by clicking the column headers of the results list.
The entries in a query results page can be used as shortcuts to editing the line in which the symbol or text string were found (or lines in that vicinity.) This is done by either double-clicking a result entry, or by selecting this entry and hitting the Enter key. As a result, &kapp; will open an editor window displaying the file referred to in the selected entry, and set the cursor to the beginning of the appropriate line.
If a query results in a single entry, this entry is automatically selected for display.
The results of a query can be refreshed by clicking the Refresh Query button to the right of the query window, or by using the context menu. This command is useful to rerun queries after the database has changed (such as after a Rebuild Database command had been issued).
Query results pages can be closed by either clicking the icon on their tab, by clicking on the Close Query button to the right of the query window, by using the context menu (available by right-clicking the page's tab), or by selecting the CscopeClose Query main-menu command.
If the query window is not visible when a query is executed, it is temporarily displayed, and then re-hidden when the user selects an entry for viewing.
Query Results Options
Right-clicking a query result in either a query window or a call-tree dialogue displays a context menu. This menu includes several actions that can be used to either extract information or fine tune these results.
Copy FileCopies the file path part of a result record to the clipboard (the copy commands are available depending on the position of the mouse cursor).Copy FunctionCopies the function name part of a result record to the clipboard.Copy LineCopies the line number part of a result record.Copy TextCopies the function name part of a result record to the clipboard.Filter...Displays the Filter Query Results dialogue. See the section Filtering Query Results for a detailed description of this option.Show AllDisplays all query results. This option reverts the effects of any filters previously applied.Remove ItemPermanently removes a record from a query results window. This action can only be undone by rerunning the query.Filtering Query Results
It is often the case the a query results in an abundance of information. &kapp; allows the user to filter query results in order to show only those results that the user finds interesting, an action referred to as "Filtering". Filtering is done by matching patterns on any of the query record fields (file name, function, line number and line text).
The Filter Query Results dialogue is invoked from the query context menu (see Query Result Options).
The Filter Query Results dialogueThe Filter Query Results dialogueSearch ForEnter the pattern to match in the query result records. This pattern is interpreted based on the Search Type selection.Search InThe record field in which to look for the search pattern. By default, this is the field over which the context menu was invoked.Search TypeDefines the way in which the pattern should be interpreted.Plain TextChoose this option to treat the pattern as a simple text string to search for.RegExpChoose this option to treat the pattern as a regular expression.Simplified RegExpChoose this option to treat the pattern as a simplified regular expression (a-la file expressions in a Unix shell).Case SensitiveCheck for a case sensitive search, uncheck for a case insensitive one.OKFilters the query results based on the given information.CancelCloses the dialogue without filtering the results.Displaying Call-Trees and Graphs
Tracing a sequence of calls in the code base is a common task in code analysis. To facilitate this task, &kapp; offers two mechanisms for visualising the relationships between different functions in a project: the Call-Tree and the Call-Graph. Both of these mechanisms are provided through the Call Graph Dialogue which can be invoked on a function name in a similar way to a regular Cscope query.
Call Trees
The Call-Tree has two modes, "Called Functions" and "Calling Functions". In the first case, the call chain starts with a root function, and goes on to display all the functions it references. The second mode shows all functions calling the root function. In both modes each function in the second level can be further expanded to show functions calling it (or functions it calls). This process can be further applied to functions in the third level, an so on.
Both modes use a standard tree widget to display the call chain. Expanding a function to the next level is performed by clicking the plus sign to the left of the function's name. Double-clicking a function (or selecting it and then hitting Enter) points the editor to the call's actual text. Right-clicking an entry provides a popup-menu with further options, similar to the query results menu (see Query Result Options).
A Call-TreeA Call-Tree in "Called Functions" modeCall Graphs
A Call-Tree often misses the true nature of a call sequence, since many such sequences contain loops, that is, functions calling back functions that precede them in the sequence. (Recursive calls provide a natural example for such a state of affairs.) A Call-Graph provides a more accurate description of the relationships between functions by depicting calls using a directed graph. Each node in the graph represents a function and each edge a function call. An edge is directed from the caller to the callee.
A Call-GraphA Call-Graph
When a Call-Graph is created, it only displays a single function. Right-clicking on this function opens a popup menu that allows the user to display or hide either the functions called by or calling to this one. This menu consists of the following entries:
Called FunctionsShowShows all functions called by this one.Called FunctionsList/Filter...Displays a detailed list of called functions. This list can also be used to select which calling functions to show.Called FunctionsHideRemoves any functions called by this one. This will also remove any unconnected graph components resulting from the removal of the corresponding nodes.Calling FunctionsShowShows all functions calling this one.Calling FunctionsList/Filter...Displays a detailed list of calling functions. This list can also be used to select which calling functions to show.Calling FunctionsHideRemoves any functions calling this one. This will also remove any unconnected graph components resulting from the removal of the corresponding nodes.This FunctionFind DefinitionQueries the database for the definition of the selected function.This FunctionRemoveDeletes the selected node from the graph.
Another popup menu is displayed when an arrow head is right-clicked:
Open CallOpens an editor page at the location of the call represented by this edge.