xref: /xnu-8020.121.3/tools/lldbmacros/coreanalytics.py (revision fdd8201d7b966f0c3ea610489d29bd841d358941)
1*fdd8201dSApple OSS Distributionsfrom __future__ import absolute_import
2*fdd8201dSApple OSS Distributions
3*fdd8201dSApple OSS Distributionsfrom xnu import *
4*fdd8201dSApple OSS Distributions
5*fdd8201dSApple OSS Distributions@lldb_command("showcoreanalyticsformatstr")
6*fdd8201dSApple OSS Distributionsdef PrintCoreAnalyticsFormatStr(cmd_args=None):
7*fdd8201dSApple OSS Distributions    """ Pretty prints the full format string for a core analyics event
8*fdd8201dSApple OSS Distributions        Usage: showcoreanalyticsformatstr <event>
9*fdd8201dSApple OSS Distributions    """
10*fdd8201dSApple OSS Distributions    if not cmd_args:
11*fdd8201dSApple OSS Distributions        raise ArgumentError("Please specify an event.")
12*fdd8201dSApple OSS Distributions        return
13*fdd8201dSApple OSS Distributions    #event_ptr = kern.GetValueFromAddress(cmd_args[0], "struct _ca_event *").GetSBValue().GetValueAsUnsigned()
14*fdd8201dSApple OSS Distributions    #print(event_ptr)
15*fdd8201dSApple OSS Distributions    event = kern.GetValueFromAddress(cmd_args[0], "struct _ca_event *")
16*fdd8201dSApple OSS Distributions    event_name = str(event.format_str)
17*fdd8201dSApple OSS Distributions    print(event_name)
18*fdd8201dSApple OSS Distributions    curr = event.format_str.GetSBValue().GetValueAsUnsigned()
19*fdd8201dSApple OSS Distributions    offset = len(event_name) + 1
20*fdd8201dSApple OSS Distributions    while True:
21*fdd8201dSApple OSS Distributions        val = kern.GetValueFromAddress(curr + offset, "char *")
22*fdd8201dSApple OSS Distributions        as_string = str(val)
23*fdd8201dSApple OSS Distributions        if len(as_string) == 0:
24*fdd8201dSApple OSS Distributions            break
25*fdd8201dSApple OSS Distributions        offset = offset + len(as_string) + 1
26*fdd8201dSApple OSS Distributions        print(as_string)
27