You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/codeql/codeql-for-visual-studio-code/using-the-codeql-model-editor.rst
+28-8Lines changed: 28 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ When you open the model editor, it analyzes the currently selected CodeQL databa
18
18
19
19
The model editor has two different modes:
20
20
21
-
- Application mode (default view): The editor lists each external framework used by the selected CodeQL database. When you expand a framework, a list of all calls to and from the external API is shown with the options available to model dataflow through each call. This mode is most useful for improving the CodeQL results for the specific codebase.
21
+
- Application mode (default view): The editor lists each external framework used by the selected CodeQL database. When you expand a framework, a list of all calls to and from the external API is shown with the options available to model dataflow through each call. This mode is most useful for improving the CodeQL results for a specific codebase.
22
22
23
23
- Dependency mode: The editor identifies all of the publicly accessible APIs in the selected CodeQL database. This view guides you through modeling each public API that the codebase makes available. When you have finished modeling the entire API, you can save the model and use it to improve the CodeQL analysis for all codebases that use the dependency.
24
24
@@ -28,38 +28,49 @@ Displaying the CodeQL model editor
28
28
#. Open your CodeQL workspace in VS Code, for example, the ``vscode-codeql-starter`` workspace.
29
29
If you haven't updated the ``ql`` submodule for a while, update it from ``main`` to ensure that you have the queries used to gather data for the model editor.
30
30
#. Open the CodeQL extension and select the CodeQL database that you want to model from the "Databases" section of the left side pane.
31
-
#. Use the command palette to run the “CodeQL: Open Model Editor (Beta)” command.
32
-
#. The CodeQL model editor will open in a new tab and run a series of telemetry queries to identify APIs in the code.
31
+
#. In the left side panel, expand the "CodeQL method modeling" section and click **Start modeling** to display the model editor.
32
+
#. The CodeQL model editor runs a series of telemetry queries to identify APIs in the code and opens in a new tab.
33
33
#. When the queries are complete, the APIs that have been identified are shown in the editor.
34
34
35
35
Modeling the calls your codebase makes to external APIs
You typically use this approach when you are looking at a specific codebase where you want to improve the precision of CodeQL results. This is usually when the codebase uses frameworks or libraries that are not supported by CodeQL and if the source code of the framework or library is not included in the analysis.
38
+
You typically use this approach when you are looking at a specific codebase where you want to improve the precision of CodeQL results. This is useful when the codebase uses frameworks or libraries that are not supported by CodeQL and if the source code of the framework or library is not included in the analysis.
39
39
40
40
#. Select the CodeQL database that you want to improve CodeQL coverage for.
41
41
#. Display the CodeQL model editor. By default the editor runs in application mode, so the list of external APIs used by the selected codebase is shown.
:alt:Screenshot of the "Application mode" view of the CodeQL model pack editor in Visual Studio Code showing three of the external frameworks used by the "sofa-jraft" codebase.
45
+
:alt:Screenshot of the "Application mode" view of the CodeQL model pack editor in Visual Studio Code showing two of the external Java frameworks used by the "sofa-jraft" codebase.
46
46
47
47
#. Click to expand an external API and view the list of calls from the codebase to the external dependency.
48
-
#. Click **View** associated with an API call or method to show where it is used in your codebase.
:alt:Screenshot of the "Application mode" view of the CodeQL model pack editor in Visual Studio Code showing the calls to the "rocksdbjni" framework ready for modeling. The "View" option for the first call is highlighted with a dark orange outline.
53
52
54
-
#. When you have determined how to model the call or method, define the **Model type**.
53
+
#. Click **View** associated with an API call or method to show where it is used in your codebase.
:alt:Screenshot of a file showing a place where your codebase calls the API is highlighted with a dark orange outline.
58
+
59
+
#. The file containing the first call from your codebase to the API is opened and a "CodeQL methods usage" view opened (typically this is co-located with the "Problems" and "Terminal" views. The "CodeQL methods usage" view lists of all the calls from your code to the API, grouped by method. You can click through each use to decide how to a model the method.
:alt:Screenshot of the "CodeQL methods usage" view. The currently displayed method call is highlighted blue.
64
+
65
+
#. When you have determined how to model the call or method, define the **Model type** in either the main model editor tab, or in the "CodeQL method modeling" tab.
55
66
#. The remaining fields are updated with available options:
56
67
57
68
- **Source**: choose the **Output** element to model.
58
69
- **Sink**: choose the **Input** element to model.
59
70
- **Flow summary**: choose the **Input** and **Output** elements to model.
60
71
61
72
#. Define the **Kind** of dataflow for the model.
62
-
#. When you have finished modeling, click **Save all** or **Save** (shown at the bottom right of each expanded list of calls). The percentage of calls modeled in the editor is updated.
73
+
#. When you have finished modeling, display the main model editor and click **Save all** or **Save** (shown at the bottom right of each expanded list of methods). The percentage of methods modeled in the editor is updated.
63
74
64
75
The models are stored in your workspace at ``.github/codeql/extensions/<codeql-model-pack>``, where ``<codeql-model-pack>`` is the name of the CodeQL database that you selected. That is, the name of the repository, hyphen, the language analyzed by CodeQL.
65
76
@@ -114,6 +125,15 @@ The models are stored in a series of YAML data extension files, one for each pub
114
125
115
126
The editor will create a separate model file for each package that you model.
116
127
128
+
Modeling methods that can be called in different ways
Some methods behave differently according to how they are called. In this case, once you have created one model for the method, you can add a second model using the **+** button in the method row.
:alt:Screenshot of the "Dependency mode" view of the CodeQL model pack editor in Visual Studio Code showing one model for the ``com.alipay.sofa.jraft.option.BallotBoxOptions.getClosureQueue()`` method. The "+" button is outlined in dark orange. Click this button to create a second model for the method.
0 commit comments