From 81f4fcc95f6c0d482dd0acd14e43eb96b2bc0e6f Mon Sep 17 00:00:00 2001
From: pompolic <pompolic@special-circumstanc.es>
Date: Mon, 31 Oct 2022 19:24:23 +0100
Subject: [PATCH] (WIP) Partial fix for extra entries in info_strings

---
 gdb-port/top-level-parse.py | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/gdb-port/top-level-parse.py b/gdb-port/top-level-parse.py
index 0ec68aa..0d9e9f2 100644
--- a/gdb-port/top-level-parse.py
+++ b/gdb-port/top-level-parse.py
@@ -386,7 +386,6 @@ class TopLevelParse:
 
 	# TODO: get_avg_mem_use_all_arenas, get_total_mem_use
 
-	# TODO: remove first printing loop
 	def print_input_chunk(self, token, token_list, rows, start, end):
 		#print("print_input_chunk(): start: ", start, "end: ", end)
 		w = end-start
@@ -412,12 +411,16 @@ class TopLevelParse:
 
 			try:
 				hpr = HParseResult(int(hparseresult_addr, 16))
+				if token.address != hpr.ast.address:
+					raise RuntimeError("confused the info strings")
 				info_strings.append(" ".join([hpr.str_no_deref(), str(tokenmap_entry)]))
-			except:
+			except Exception as err:
+				print("Got exception when validating tokeninfo: ", err)
 				info_strings.append(" ".join(["invalid", str(tokenmap_entry)]))
 
 			if tokenmap_entry['end'] <= end:
-				del self.tokens_from_previous_chunk[index]
+				del self.tokens_from_previous_chunk[index] # TODO: Maybe it's a bad idea to modify a container you're iterating on
+
 
 		while printing_index < len(token_list):
 			token = token_list[printing_index]
@@ -435,7 +438,13 @@ class TopLevelParse:
 			try:
 				hpr = HParseResult(int(hparseresult_addr, 16))
 				info_strings.append(" ".join([hpr.str_no_deref(), str(tokenmap_entry)]))
-			except:
+				if token.address != hpr.ast.address:
+					raise RuntimeError("confused the info strings")
+			except Exception as a: #DEBUG
+				print(a, "type:", type(a))
+				print(traceback.format_exc())
+				gdb.execute("list")
+				gdb.execute("backtrace")
 				info_strings.append(" ".join(["invalid", str(tokenmap_entry)]))
 
 			if tokenmap_entry['end'] > end:
-- 
GitLab