about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorTheofilos Augoustis <theofilos.augoustis@gmail.com>2025-11-20 10:11:56 +0000
committerTheofilos Augoustis <theofilos.augoustis@gmail.com>2025-11-20 10:16:34 +0000
commitffb7dfc0bb2c2504aa75a8dbcc80d1665096bdd1 (patch)
tree0f87baf1b3c234d2dd120f2bb7120ba11e2f5bf6
parent1f9aa5984b74ccff15dcb51b7983443d1a19e55d (diff)
downloadfocaccia-ffb7dfc0bb2c2504aa75a8dbcc80d1665096bdd1.tar.gz
focaccia-ffb7dfc0bb2c2504aa75a8dbcc80d1665096bdd1.zip
Match thread IDs with those from event log
-rw-r--r--src/focaccia/qemu/_qemu_tool.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/focaccia/qemu/_qemu_tool.py b/src/focaccia/qemu/_qemu_tool.py
index fdcf579..b5008e1 100644
--- a/src/focaccia/qemu/_qemu_tool.py
+++ b/src/focaccia/qemu/_qemu_tool.py
@@ -177,7 +177,12 @@ class GDBServerStateIterator:
                                     from_state=first_state,
                                     skipped_events=skipped_events)
         event = self._events.match(first_state)
+        
+        self._thread_map = {
+            event.tid: self.current_tid()
+        }
         info(f'Synchronized at PC={hex(first_state.read_pc())} to event:\n{event}')
+        debug(f'Thread mapping at this point: {hex(event.tid)}: {hex(self.current_tid())}')
 
     def current_state(self) -> ReadableProgramState:
         return GDBProgramState(self._process, gdb.selected_frame(), self.arch)
@@ -219,10 +224,16 @@ class GDBServerStateIterator:
             self._step()
             if self._is_exited():
                 raise StopIteration
+
             # Check if new thread was created
             if syscall.creates_thread:
                 new_tid = self.current_state().read_register(self.arch.get_syscall_reg())
+                event_new_tid = post_event.registers[self.arch.get_syscall_reg()]
+                self._thread_map[event_new_tid] = new_tid
                 info(f'New thread created TID={hex(new_tid)} corresponds to native {hex(event.tid)}')
+                debug('Thread mapping at this point:')
+                for event_tid, tid in self._thread_map.items():
+                    debug(f'{hex(event_tid)}: {hex(tid)}')
 
             return GDBProgramState(self._process, gdb.selected_frame(), self.arch)
 
@@ -311,6 +322,9 @@ class GDBServerStateIterator:
     def _step(self):
         gdb.execute('si', to_string=True)
 
+    def current_tid(self) -> int:
+        return gdb.selected_inferior().threads()[0].ptid[1]
+
     def context_switch(self, thread_number: int) -> None:
         gdb.execute(f'thread {thread_number}')
         self._thread_num = thread_number