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