From f64791853d0e3fc26eae68418975fbfbd29ece03 Mon Sep 17 00:00:00 2001
From: pompolic <pompolic@special-circumstanc.es>
Date: Mon, 8 May 2023 22:02:10 +0200
Subject: [PATCH] Set TopLevelParse unit test to use HArena* instead of a
 HArena

---
 gdb-port/tests/unit/top-level-parse.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/gdb-port/tests/unit/top-level-parse.py b/gdb-port/tests/unit/top-level-parse.py
index 376381c..48b17d1 100644
--- a/gdb-port/tests/unit/top-level-parse.py
+++ b/gdb-port/tests/unit/top-level-parse.py
@@ -4,11 +4,11 @@ class TopLevelParseStateManagement(unittest.TestCase):
 	@classmethod
 	def setUpClass(cls):
 		cls._harena_t = gdb.lookup_type("HArena")
-		cls._arena = gdb.parse_and_eval("malloc(sizeof(HArena))").cast(cls._harena_t.pointer()).dereference() # Quick and dirty way to allocate something in the process GDB is debugging (the inferior)
+		cls._arena = gdb.parse_and_eval("malloc(sizeof(HArena))").cast(cls._harena_t.pointer()) # Quick and dirty way to allocate something in the process GDB is debugging (the inferior)
 		cls._hps_t = gdb.lookup_type("HParseState")
 		cls._test_parse_state = gdb.parse_and_eval("malloc(sizeof(HParseState))").cast(cls._hps_t.pointer()).dereference()
 		# TODO: make this independent of endianness and pointer size
-		gdb.selected_inferior().write_memory(int(cls._test_parse_state.address)+(cls._hps_t['arena'].bitpos//8), int(cls._arena.address).to_bytes(8, 'little')) # horrible, horrible way to set the 
+		gdb.selected_inferior().write_memory(int(cls._test_parse_state.address)+(cls._hps_t['arena'].bitpos//8), int(cls._arena).to_bytes(8, 'little')) # horrible, horrible way to set parse_state->arena
 		cls._hps_t = cls._test_parse_state.address.dereference() # "refresh" the gdb.Value, since the effects of .write_memory() don't seem to show up
 
 	def setUp(self):
@@ -87,7 +87,7 @@ class TopLevelParseStateManagement(unittest.TestCase):
 		self.top_level_parse.parser_objs[32] = self.parser1
 		self.top_level_parse.enter_h_do_parse(16, self._arena, self.parser1.address)
 		self.top_level_parse.enter_h_arena_malloc_raw(256)
-		self.assertEqual(self.parser1.bytes_used[int(self._arena.address)], 256)
+		self.assertEqual(self.parser1.bytes_used[int(self._arena)], 256)
 
 	# A bit hacky: relying on the top_level_parse initialized by top-level-parse.py, because we have no reference to the testcase
 	@unittest.skipIf(top_level_parse.memory_stat_method == HammerMemoryStatisticsMethod.DETAILED_ARENA_STATS, "malloc-based allocation counts disabled")
@@ -96,7 +96,9 @@ class TopLevelParseStateManagement(unittest.TestCase):
 		self.top_level_parse.parser_objs[32] = self.parser1
 		self.ps1.push(self.parser1, self._arena)
 		self.top_level_parse.enter_h_arena_malloc_raw(256)
-		self.assertEqual(self.top_level_parse.parser_stacks[-1].p_stack[-1].bytes_used[int(self._arena.address)], 256)
+		# If breakpoint mode doesn't use HArena* already
+		#self.assertEqual(self.top_level_parse.parser_stacks[-1].p_stack[-1].bytes_used[int(self._arena.address)], 256)
+		self.assertEqual(self.top_level_parse.parser_stacks[-1].p_stack[-1].bytes_used[int(self._arena)], 256)
 
 	def test_enter_h_arena_malloc_raw_no_parser(self):
 		self.top_level_parse.parser_stacks.append(self.ps1)
-- 
GitLab