Finding A Symbol Using trace.ual

From OC Systems Wiki!
Revision as of 15:42, 15 March 2017 by GVincentCastellano (talk | contribs) (Created page with "Category:Recipes Category:Trace Suppose you want to apply a probe to an <code>open()</code> system call, for example because you want to stub it for a unit test. You...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Suppose you want to apply a probe to an open() system call, for example because you want to stub it for a unit test. You want to know exactly which open() call to instrument, but there seem to be many "open-like" functions defined in various shared object modules and it's not clear which one you want.

One approach is to use trace.ual to find out which function your test driver ends up calling. You could build a simple trace configuration file to report on every call to a function with "open" in its name:

PROBE CONFIGURATION FILE FOR TRACE VERSION 2.1.0

Trace "*open*" in "*"

apformat will report on every such routine that gets called from your driver. This might be so many that it's still not obvious which one is specific to the test case you're working on. To narrow down the results, you would add a Trigger so that only calls from within a particular driver routine were traced:

PROBE CONFIGURATION FILE FOR TRACE VERSION 2.1.0

Trigger extern:"test_heartbeat_update()"

Trace "*open*" in "*"

Then the apformat output might show you:

  [Enter : extern:"test_heartbeat_update()"
  Called from ==> extern:"main()" at line 3370 (hb_ut.c)
   at 11:17:05.149592000
    [Enter : extern:"open_params_file()"
    Called from ==> "hb.c":"read_params()" at line 418 (hb.c)
     at 11:17:05.149917000
      [Enter : extern:"__open64()" in "libpthread.so"
      Called from ==> "hb.c":"read_params()" at line 425 (hb.c)
       at 11:17:05.149918000
      ]Leave : extern:"__open64()" in "libpthread.so"
       at 11:17:05.149925000
    ]Leave : extern:"open_params_file()"
     at 11:17:05.149928000
  ]Leave : extern:"test_heartbeat_update()"
   at 11:17:05.150276000

Now it's clear that you want to instrument extern:"__open64()" in "libpthread.so". Notice the trace also captures an application symbol whose name happened to match the wildcard.

Alternatively, instead of using wildcards in your trace.cfg file, you could populate the trace.cfg file by running apsymbols -a on your executable and doing your own filtering on the symbols found, for example:

apsymbols -a driver.exe | grep open64 >> driver.exe.trace.cfg