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