22 return 'Unknown(' + str(v) +
')'
30 """A handy wrapper over ctypes.Structure"""
34 self.
ctype = Descriptor._GetCtype(fields)
38 return self.
ctype.from_address(address)
41 def _GetCtype(fields):
46 if isinstance(type, Enum):
47 raw_fields.append((
'_raw_' + name, type.type))
50 raw_fields.append(field)
52 class Raw(ctypes.Structure):
56 def __getattribute__(self, name):
58 return wrappers[name].from_raw(
59 getattr(self,
'_raw_' + name))
61 return ctypes.Structure.__getattribute__(self, name)
64 return '{' +
', '.
join(
65 '%s: %s' % (field, self.__getattribute__(field))
66 for field, _
in fields) +
'}'
74MINIDUMP_HEADER =
Descriptor([(
'signature', ctypes.c_uint32),
75 (
'version', ctypes.c_uint32),
76 (
'stream_count', ctypes.c_uint32),
77 (
'stream_directories_rva', ctypes.c_uint32),
78 (
'checksum', ctypes.c_uint32),
79 (
'time_date_stampt', ctypes.c_uint32),
80 (
'flags', ctypes.c_uint64)])
82MINIDUMP_LOCATION_DESCRIPTOR =
Descriptor([(
'data_size', ctypes.c_uint32),
83 (
'rva', ctypes.c_uint32)])
85MINIDUMP_STREAM_TYPE = {
86 'MD_UNUSED_STREAM': 0,
87 'MD_RESERVED_STREAM_0': 1,
88 'MD_RESERVED_STREAM_1': 2,
89 'MD_THREAD_LIST_STREAM': 3,
90 'MD_MODULE_LIST_STREAM': 4,
91 'MD_MEMORY_LIST_STREAM': 5,
92 'MD_EXCEPTION_STREAM': 6,
93 'MD_SYSTEM_INFO_STREAM': 7,
94 'MD_THREAD_EX_LIST_STREAM': 8,
95 'MD_MEMORY_64_LIST_STREAM': 9,
96 'MD_COMMENT_STREAM_A': 10,
97 'MD_COMMENT_STREAM_W': 11,
98 'MD_HANDLE_DATA_STREAM': 12,
99 'MD_FUNCTION_TABLE_STREAM': 13,
100 'MD_UNLOADED_MODULE_LIST_STREAM': 14,
101 'MD_MISC_INFO_STREAM': 15,
102 'MD_MEMORY_INFO_LIST_STREAM': 16,
103 'MD_THREAD_INFO_LIST_STREAM': 17,
104 'MD_HANDLE_OPERATION_LIST_STREAM': 18,
108 Enum(ctypes.c_uint32, MINIDUMP_STREAM_TYPE)),
110 MINIDUMP_LOCATION_DESCRIPTOR.ctype)])
113 (
'SizeOfInfo', ctypes.c_uint32),
114 (
'Flags1', ctypes.c_uint32),
115 (
'ProcessId', ctypes.c_uint32),
116 (
'ProcessCreateTime', ctypes.c_uint32),
117 (
'ProcessUserTime', ctypes.c_uint32),
118 (
'ProcessKernelTime', ctypes.c_uint32),
119 (
'ProcessorMaxMhz', ctypes.c_uint32),
120 (
'ProcessorCurrentMhz', ctypes.c_uint32),
121 (
'ProcessorMhzLimit', ctypes.c_uint32),
122 (
'ProcessorMaxIdleState', ctypes.c_uint32),
123 (
'ProcessorCurrentIdleState', ctypes.c_uint32),
126MINIDUMP_MISC1_PROCESS_ID = 0x00000001
132 obj = ctypes.py_object(buf)
133 address = ctypes.c_void_p()
134 length = ctypes.c_ssize_t()
135 ctypes.pythonapi.PyObject_AsReadBuffer(obj, ctypes.byref(address),
136 ctypes.byref(length))
141 """Class for reading minidump files."""
142 _HEADER_MAGIC = 0x504d444d
151 if self.
header.signature != MinidumpFile._HEADER_MAGIC:
152 raise Exception(
'Unsupported minidump header magic')
154 offset = self.
header.stream_directories_rva
155 for _
in range(self.
header.stream_count):
157 offset += MINIDUMP_DIRECTORY.size
161 if dir.stream_type ==
'MD_MISC_INFO_STREAM':
162 info = self.
Read(MINIDUMP_MISC_INFO_2, dir.location.rva)
163 if info.Flags1 & MINIDUMP_MISC1_PROCESS_ID != 0:
164 return info.ProcessId
182 return int(f.GetProcessId())
def __init__(self, fields)
def __init__(self, type, name2value)
def Read(self, what, offset)
def __init__(self, minidump_name)
def __exit__(self, type, value, traceback)
static void append(char **dst, size_t *count, const char *src, size_t n)
def GetProcessIdFromDump(path)
static SkString join(const CommandLineFlags::StringArray &)