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