For the complete documentation index, see llms.txt. This page is also available as Markdown.

Common Queries

The following examples were written for the source code of the VLC Media Player v3.0.8. You can download the source code here.

Basic Analysis

Methods

  • List all methods that match .*parse.* to the shell

ocular> cpg.method.name(".*parse.*").name.l
  • Dump all methods that match .*parse.* to the shell (syntax-highlighted)

ocular> cpg.method.name(".*parse.*").dump
  • Create K-V pair of all methods that match .*parse.* and their code

ocular> cpg.method.name(".*parse.*").map( m=> (m.name, m.start.dump)).l
  • Dump all methods that match .*parse.* to file (no highlighting)

ocular> cpg.method.name(".*parse.*").dumpRaw |> "/tmp/foo.c"
  • View all methods that match .*parse.* in a pager (e.g., less)

ocular> browse(cpg.method.name(".*parse.*").dump)
  • Dump dot representations of ASTs for all methods that match parse into file

ocular> cpg.method.name("parse_public_key_packet").dot |> "/tmp/foo.dot"
  • Find all local variables defined in a method

ocular> cpg.method.name("parse_public_key_packet").local.name.l
  • Find which file and line number they are in

  • Find the type of the first local variable defined in a method

  • Find all outgoing calls (call-sites) in a method

  • Find which method calls a method

Types and Filters

  • List all local variables of type vlc_.*

  • Find member variables of a struct

  • Find local variables and filter them by their type

  • Which method are they used in?

  • Get the filenames where these methods are

Insights

Overview

  • Identify functions with more than 4 parameters

  • Identify functions with > 4 control structures (cyclomatic complexity)

  • Identify functions with more than 500 lines of code

  • Identify functions with multiple return statements

  • Identify functions with more than 4 loop statements (including loops nested inside other loops)

  • Identify functions with nesting depth larger than 3

Calls into libraries

  • All names of external methods used by the program

  • All calls to strcpy

  • All methods that call strcpy

  • Looking into parameters: second argument to sprintf is NOT a literal

  • Quickly see this method above

Last updated

Was this helpful?