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