2 Replies
      Latest reply on Jan 8, 2019 3:30 PM by dmaclach
      dmaclach Level 1 Level 1 (0 points)

        If I had a pointer (say to a mach-o header) and I wanted to resolve that to the name/path of the image it came from, is there any magic function to do that in a custom instrument definition?

        • Re: image name for pointer in custom instrument
          cwoolf Apple Staff Apple Staff (40 points)

          Not really... no. 

           

          If you had a pointer to a function in the text segment you could create an "Executable Code" engineering type if you had the process object and the text address, and at display time it will display the symbol name and file (not currently the path though).  Something like: "_GLOBAL__sub_l_iostream.cpp libc++.1.dylib".   See the "Static Initializers" instrument in the library for an example of that.

           

          I know that's kind of a stretch.

            • Re: image name for pointer in custom instrument
              dmaclach Level 1 Level 1 (0 points)

              That's actually not that bad. It comes up with the naked address and the image name which is sufficient for my needs.

               

              Code for folks reading this in the future:

               

               

              <ktrace-interval-schema>
                  <id>com-google-dyld-objc-init-schema</id>
                  <title>dyld ObjC Init</title>
                  <start-pattern>
                    <class>31</class>
                    <subclass>7</subclass>
                    <code>8</code>
                    <function>1</function>
                    <thread>?thread</thread>
                    <arg2>?initializer</arg2>
                  </start-pattern>
                  <end-pattern>
                    <class>31</class>
                    <subclass>7</subclass>
                    <code>8</code>
                    <function>2</function>
                  </end-pattern>
                  <start-column>
                    <mnemonic>start</mnemonic>
                    <title>Start</title>
                    <type>start-time</type>
                  </start-column>
                  <duration-column>
                    <mnemonic>duration</mnemonic>
                    <title>Duration</title>
                    <type>duration</type>
                  </duration-column>
                  <column>
                    <mnemonic>process</mnemonic>
                    <title>Process</title>
                    <type>process</type>
                    <expression>(process-from-thread ?thread)</expression>
                  </column>
                  <column>
                    <mnemonic>image</mnemonic>
                    <title>Image</title>
                    <type>text-symbol</type>
                    <expression>(engineering-type text-symbol (process-from-thread ?thread) ?initializer)</expression>
                  </column>
                </ktrace-interval-schema>
              

               

              Thanks cwolff!