Skip to content

Commit

Permalink
Merge pull request #14 from matan1008/bugfix/terminate-unknown-thread
Browse files Browse the repository at this point in the history
Trace: Fix handling unknown thread.
  • Loading branch information
matan1008 authored Dec 5, 2021
2 parents 670f164 + 8e27ab7 commit c8b3aaa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pykdebugparser/trace_handlers/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ def __str__(self):
class TraceDataThreadTerminate:
ktraces: List
tid: int
pid: int
pid: int = None
name: str = ''

def __str__(self):
rep = f'Thread terminated tid: {self.tid}, pid: {self.pid}'
rep = f'Thread terminated tid: {self.tid}'
if self.pid is not None:
rep += f', pid: {self.pid}'
if self.name:
rep += f', name: {self.name}'
return rep
Expand Down Expand Up @@ -122,7 +124,7 @@ def handle_trace_data_exec(parser, events):

def handle_trace_data_thread_terminate(parser, events):
tid = events[0].values[0]
event = TraceDataThreadTerminate(events, tid, parser.threads_pids[tid])
event = TraceDataThreadTerminate(events, tid, parser.threads_pids.get(tid))
event.name = parser.tids_names.get(tid, '')
return event

Expand Down
12 changes: 12 additions & 0 deletions tests/traces/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,15 @@ def test_trace_data_thread_terminate(traces_parser):
ret = list(traces_parser.feed_generator(events))
assert len(ret) == 1
assert str(ret[0]) == 'Thread terminated tid: 269178, pid: 61, name: terminated thread'


def test_trace_data_thread_terminate_missing_tid(traces_parser):
events = [
Kevent(timestamp=1805581011060,
data=(b'z\x1b\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),
values=(269178, 0, 0, 0), tid=479, debugid=117440524, eventid=117440524, func_qualifier=0)
]
ret = list(traces_parser.feed_generator(events))
assert len(ret) == 1
assert str(ret[0]) == 'Thread terminated tid: 269178'

0 comments on commit c8b3aaa

Please sign in to comment.